对齐左边的UIButton的图像和UILabel

时间:2018-05-23 05:03:58

标签: ios objective-c uibutton

我目前有:
enter image description here

使用此代码:

button.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
button.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);

我想要实现的目标是:
enter image description here

图像和UILabel应位于UIButton的左侧,而不是位于中间。

2 个答案:

答案 0 :(得分:0)

尝试contentHorizontalAlignment属性。

<强>目标C

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

<强>夫特

button.contentHorizontalAlignment = .left

答案 1 :(得分:0)

要在Interface Builder中完成此操作,您只需更改“alignment”属性....

1.在按钮的属性检查器中将对齐属性更改为第一个选项

enter image description here

<强> 2。这将是您的输出

enter image description here

3.如果你想在图像和标题之间留出一些空间,你可以从尺寸检查器给出(只是在标题插入的左边属性中给出一些空间)

enter image description here

4.最终输出

enter image description here