场景是我想在点击按钮后更改按钮的图像。我确实喜欢这样:
func setImage(name: String, button: UIButton)
{
let image = UIImage(contentsOfFile: name) as UIImage?
button.setImage(image, forState: .Normal)
}
@IBAction func ReadValueButtonClicked(sender: UIButton) {
setImage("ic_operation_start_indications_normal.png", button: sender)
}
这根本不会带来任何改变。
有什么建议吗?
最佳答案
您需要使用 UIImagecontentsOfFile
初始值设定项指定完整路径。如果您的资源包中只有图像的文件名,请使用 imageNamed:
初始值设定项。
关于ios - 如何在点击后更改 UIButton 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33421580/