【发布时间】:2019-05-14 19:29:31
【问题描述】:
我有一个 UIButton 已禁用。这个UIButton 旁边有一个图像作为图标。我认为由于它被禁用,图像的色调是灰色的。
我已经尝试将情节提要中的按钮设置为自定义,并在此处更改了色调,但没有成功。
我也试过下面的代码:
@IBOutlet weak var drivenKmDisplay: UIButton!
let color = UIColor(red: 0/255, green: 22/255, blue: 60/255, alpha: 1)
func setDrivenKm(drivenKm: Int) {
drivenKmDisplay.isEnabled = false
let string = String(drivenKm) + " km"
drivenKmDisplay.setTitle(string, for: .disabled)
let icon = UIImage(named: "timeline")!
drivenKmDisplay.setImage(icon, for: .normal)
drivenKmDisplay.imageView?.contentMode = .scaleAspectFit
drivenKmDisplay.imageEdgeInsets = UIEdgeInsets(top: 0, left: -15, bottom: 0, right: 0)
drivenKmDisplay.tintColor = color
}
【问题讨论】:
-
您可以将
UIButton的textColor配置为启用/禁用状态而不是tintColor