import UIKit
class ViewController: UIViewController {
@IBOutlet weak var buttonText: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnButtonACTION(sender: UIButton) {
buttonText.setTitle("changetext", forState: .Normal)
}
}
我正在尝试通过 Xcode 学习 Swift 语言的基础知识。我的想法是在单击按钮时更改按钮文本。但它不会改变。有什么我错过的吗?
最佳答案
您正在使用:
buttonText.setTitle("changetext", forState: .Normal)
试试这个:
buttonText.setTitle("changetext", forState: UIControlState.Normal)
关于iOS Swift 按钮文本不会在单击时更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288585/