我有UIButton,我想将它的imageView对齐到左边。 我试过的时候: self.cancelButton.imageView.contentMode = UIViewContentModeLeft;
它似乎不起作用,因为imageView仍然在中心(UIViewContentModeCenter)
但是当我使用时 self.cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
它完美地对齐了imageView。有人可以向我解释为什么这样的行为,如UIViewContentModeLeft也应该有用吗?
答案 0 :(得分:0)
任何UIControl元素都将使用 contentHorizontalAlignment 和 contentVerticalAlignment 属性来覆盖其子UIViews和UIImageViews的 contentMode 。默认的contentHorizontalAlignment将覆盖你的contentMode,直到你明确地将按钮的contentHorizontalAlignment设置为你想要的为止。