以编程方式快速更改 UIButton 的文本 [英] Changing text of UIButton programmatically swift
本文介绍了以编程方式快速更改 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、4、5 中:
In Swift 3, 4, 5:
button.setTitle("Button Title", for: .normal)
否则:
button.setTitle("Button Title", forState: UIControlState.Normal)
还必须为 button
声明一个 @IBOutlet
.
Also an @IBOutlet
has to declared for the button
.
这篇关于以编程方式快速更改 UIButton 的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文