以编程方式快速更改UIButton的文本

问题描述:

这里简单的问题。我有一个UIButton,currencySelector,我想以编程方式更改文本。这就是我所拥有的:

Simple question here. I have a UIButton, currencySelector, and I want to programmatically change the text. Here's what I have:

currencySelector.text = "foobar"

Xcode给出了错误预期声明。我做错了什么,如何更改按钮的文本?

Xcode gives me the error "Expected Declaration". What am I doing wrong, and how can I make the button's text change?

在Swift 3中:

button.setTitle("Button Title",for: .normal)

否则:

button.setTitle("Button Title", forState: UIControlState.Normal)