【发布时间】:2016-10-25 17:43:13
【问题描述】:
我正在对即将发布的应用程序进行最后润色,但我发现很难让UIButton 的背景图像中的contentMode 得到尊重。无论我指定的 contentMode 是什么,图像都会在背景中弹出,而与 contentMode 设置无关。
我查看了涵盖此主题的 post,但在我的情况下它似乎没有任何作用。
这是从viewDidLoad调用的:
// I tried putting the contentMode lines here...
myButton.imageView!.contentMode = .scaleAspectFit
myButton.contentMode = .scaleAspectFit
myButton.setBackgroundImage(UIImage(named: "myImage.png"), for: .normal)
// ...and here
// myButton.imageView!.contentMode = .scaleAspectFit
// myButton.contentMode = .scaleAspectFit
// I threw this in for S's & G's to see if it would work...it didn't
myButton.translatesAutoresizingMaskIntoConstraints = false
myButton.imageView?.translatesAutoresizingMaskIntoConstraints = true
我不确定我错过了什么,但我确信这对我来说将是一件非常愚蠢的事情。我欢迎有关如何让UIButton 的背景图像的contentMode 受到尊重的建议。感谢您的阅读。
更新
该按钮被键入为自定义按钮,而不是系统按钮。
【问题讨论】: