我已经实现了自己的自定义按钮,并且效果很好。删除UIButton上的禁用色调
import Foundation
import UIKit
class GhostYouButton: UIButton {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override var isEnabled: Bool {
didSet {
if (self.isEnabled == false) {
self.backgroundColor = UIColor.clear
self.titleLabel?.textColor = Constant.disabledGrayColor
self.tintColor = Constant.disabledGrayColor
self.borderColor = Constant.disabledGrayColor
self.borderWidth = 2
self.cornerRadius = 20
} else {
self.backgroundColor = UIColor.clear
self.titleLabel?.textColor = Constant.mainGreenColor
self.tintColor = Constant.mainGreenColor
self.borderColor = Constant.mainGreenColor
self.borderWidth = 2
self.cornerRadius = 20
}
}
}
}
设置我GhostYouButton在viewDidLoad中()被禁用:
override func viewDidLoad() {
self.nextButton.isEnabled = false
}
像我期待它因此,它会变成灰色:
但是...正如你所看到的,UIButton的标题已经淡出。我希望这是与边框完全相同的颜色。我如何做到这一点?
您需要添加按钮上方的标签,还可以设置按钮上的文字。而且可能你的看法hirarchy并不完美。 –
如果按钮本身已经有标题,那么在按钮上添加一个标签会让我觉得很奇怪。这是唯一的方法吗? –
@RutgerHuijsmans。我想你错过super.viewDidLoad()到你的覆盖func viewDidLoad()。 –