问题描述
所以我试图在单击 UIButton 时更新它的文本.我正在使用以下行来更改文本:
So I'm trying to update the text on a UIButton when I click it. I'm using the following line to change the text:
calibrationButton.titleLabel.text = @"Calibration";
我已验证文本正在更改,但是当我运行应用程序并单击按钮时,它会在一瞬间更改为校准",然后立即恢复为默认值.任何想法为什么会发生这种情况?我需要调用某种刷新函数吗?
I have verified that the text is changing, but when I run the app and I click on the button, it changes to "Calibration" for a split second and then goes right back to its default value. Any ideas why this might be happening? Is there some sort of refresh function I need to be calling?
推荐答案
在布局子视图时,UIButton 会使用自己的标题值设置其 titleLabel 的文本值,这样您就可以为这四个设置最多四个不同的字符串状态(正常、突出显示、选中、禁用).
When laying out its subviews, a UIButton will set its titleLabel's text value using its own title values, so that you can set up to four different strings for the four states (normal, highlighted, selected, disabled).
因为这个特性,直接设置titleLabel的文本不会持久化,会在布局子视图时被按钮重置.
Because of this feature, setting the titleLabel's text directly won't persist, and will be reset by the button when it lays out its subviews.
这是更改按钮状态的标题文本所必须执行的操作.
This is what you have to do to change the title text for a button's state.
[calibrationButton setTitle:@"Calibration" forState:UIControlStateNormal];
这篇关于更改 UIButton 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)