问题描述
注意:其他人也提出了类似的问题,但没有提供的答案可以解决我的问题。
这是我的代码:
@IBOutlet var testButton:UIButton!
override func viewDidLoad() {
self.testButton.setimage(UIImage(named: "icn_checkBox_")?.imageWithColor(color: CMStyle.darkBlueColor),for: .normal)
self.testButton.setimage(UIImage(named: "icn_checked")?.imageWithColor(color: CMStyle.darkBlueColor),for: .selected)
}
@IBAction func testButtonAction(_ sender: Any) {
print("INSIDE testButtonAction")
self.testButton.isSelected = !self.testButton.isSelected
print("self.testButton.isSelected: ",self.testButton.isSelected)
}
这是按钮:
。
这些是按钮的特征:
。
这是用于.normal
状态的 icn_checkBox _ 图片:
这是用于.selected
状态的 icn_checked 图片:
testButtonAction
中的代码被执行。所以我真的不明白为什么图像不改变(为什么按钮没有被选中)。