UIViewContentMode与UIControlContentHorizo​​ntalAlignment对比

时间:2013-02-02 14:43:47

标签: ios objective-c uiimageview uibutton uicontrol

我有UIButton,我想将它的imageView对齐到左边。 我试过的时候: self.cancelButton.imageView.contentMode = UIViewContentModeLeft;

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

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

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

1 个答案:

答案 0 :(得分:0)

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