我正在进行一个教程,其中保留了一个按钮和标签,并在单击按钮时更改标签文本,在教程中调用一个方法
sender.titleForState(.Normal)
但在我的Xcode中,我找不到相同的方法。
如果你想在Swift 3/4中更改UIButton
的标题
sender.setTitle("Your title", for: .normal)
斯威夫特3
试试这个
func buttonPressed(_ sender: UIButton) {
sender.setTitle("Your title", for: .normal)
}
并通过添加这样的选择器来调用此函数
youbutton.addTarget(self, action: #selector(YourController.buttonPressed(_:)), for: .touchUpInside)
将其添加到viewDidLoad()方法中
希望能帮助到你。
如果要通过单击按钮更改按钮的标题,则需要使用button'e操作方法编写代码
防爆。
@IBAction func clickOnButtonForChangeTheTitle(_ sender: UIButton)
{
sender.setTitle("I'm changing the title", for: .normal)
}