按下时更改按钮标签/文本

时间:2017-07-22 12:49:19

标签: swift button

所以我有@IBAction func button(_ sender: Any) {} 标签上写着"嘿"从一开始。

单击按钮后如何更改该文本? 无法找到任何有效的与swift相关的答案。

2 个答案:

答案 0 :(得分:4)

您可以使用:

@IBAction func button(_ sender: Any) {
    (sender as! UIButton).setTitle("newTitle", for: [])
}

或者只是:

@IBAction func buttonTapped(_ sender: UIButton) {
    sender.setTitle("newTitle", for: [])
}

答案 1 :(得分:1)

更改该功能标签中的文字:

label.text = "Hello"