【问题标题】:UIViewContentMode Vs UIControlContentHorizontalAlignmentUIViewContentMode 与 UIControlContentHorizo​​ntalAlignment
【发布时间】:2013-02-02 14:43:46
【问题描述】:

我有 UIButton,我想将它的 imageView 对齐到左。 当我尝试: self.cancelButton.imageView.contentMode = UIViewContentModeLeft;

它似乎不起作用,因为 imageView 仍然在中心(UIViewContentModeCenter)

但是当我使用 self.cancelButton.contentHorizo​​ntalAlignment = UIControlContentHorizo​​ntalAlignmentLeft;

它完美地对齐了 imageView。有人可以向我解释为什么这种行为,因为 UIViewContentModeLeft 也应该起作用吗?

【问题讨论】:

    标签: ios objective-c uiimageview uibutton uicontrol


    【解决方案1】:

    任何 UIControl 元素都将使用 contentHorizo​​ntalAlignmentcontentVerticalAlignment 属性来覆盖其子 UIView 和 UIImageView 的 contentMode。默认的 contentHorizo​​ntalAlignment 将覆盖您的 contentMode,直到您明确地将按钮的 contentHorizo​​ntalAlignment 设置为您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 2010-10-19
      • 2019-01-26
      • 2013-06-04
      • 2012-07-08
      • 1970-01-01
      相关资源
      最近更新 更多