【发布时间】:2015-11-10 10:38:07
【问题描述】:
您好,我有一个无法解决的问题。我写了一个扩展来帮助我为透明的 PNG 着色
extension UIButton {
func setImageColorForState(image: UIImage, color: UIColor, forState: UIControlState) {
let temp = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
setImage(temp, forState: forState)
tintColor = color
}
}
我使用的扩展如下:
btn.setImageColorForState(originalImage!, color: UIColor.yellowColor(), forState: .Highlighted)
btn.setImageColorForState(originalImage!, color: UIColor.grayColor(), forState: .Normal)
不知何故,它只需要最后一个状态。所以在这种情况下,高亮状态被忽略。我在这里错过了什么?
【问题讨论】: