【发布时间】:2016-09-20 23:29:29
【问题描述】:
我想为 imageView 中的图像着色。之后我想将此图像设置为按钮。
let imageView:UIImageView = UIImageView()
if let myImage = UIImage(named: "ic_star") {
let tintableImage = myImage.imageWithRenderingMode(.AlwaysTemplate)
imageView.image = tintableImage
}
imageView.tintColor = UIColor.redColor()
bestListButton.setImage(imageView.image, forState: .Normal)
这是一个 sn-p,应该可以工作,但它总是将我的按钮图像着色为蓝色。 调试器说颜色没有改变。模拟器将其更改为蓝色。
好像和我的图片背景色没有关系。
编辑和(破解)解决方案 好吧,这很奇怪。蓝色是因为在我的界面构建器中是 tintColor blue。 我把它改成了白色。现在我的星星是白色的。
但是:当我删除我的代码时,图像会变回黑色。所以颜色的变化似乎只是结合了界面生成器和代码。
编辑 2
以编程方式解决:
bestListButton.tintColor = UIColor.redColor()
【问题讨论】:
标签: swift image button colors imageview