【问题标题】:Align both image and UILabel of the UIButton in the left对齐左侧 UIButton 的图像和 UILabel
【发布时间】:2018-05-23 05:03:58
【问题描述】:

我目前有:

使用此代码:

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);

我想要实现的是:

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

【问题讨论】:

  • 您可以从尺寸检查器设置图像和标题插图
  • 可以设置按钮的Horizo​​ntalAlignment
  • 更好的解决方案是创建 UIView 并将项目添加为子视图

标签: ios objective-c uibutton


【解决方案1】:

试试contentHorizontalAlignment 属性。

Objective-C

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

斯威夫特

button.contentHorizontalAlignment = .left

【讨论】:

  • 目标中没有 .left - c.
【解决方案2】:

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

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

2。这将是您的输出

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

4.最终输出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 2016-07-11
    • 2012-12-05
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 2015-01-25
    相关资源
    最近更新 更多