UIButton上的文本更改不会阻塞 [英] Text change on UIButton doesn't stick

查看:94
本文介绍了UIButton上的文本更改不会阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的视图中有一个UIButton说停止。按下时,应该(停止播放,当然,和)将其标签更改为RTN TO ZERO。这很简单:

I have an UIButton in my View that says "STOP". When pressed, it should (stop the playback, of course, and) change its label to "RTN TO ZERO". This is straightforward:

stopButton.titleLabel.text = @RTN TO ZERO;

但是,更改仅在分割秒后显示。它不粘。我假设按钮(按下时突出显示)接受并显示新标签,但不知何故,高亮只是稍后反转,将按钮恢复到按下之前的样子,而不遵守标签文本更改。
该按钮是在IB中构思的,而不是以编程方式。

However, the change appears only for a split second. It doesn't stick. I assume that the button (which gets highlighted when pressed) accepts and displays the new label, but somehow the highlight is reversed only later, restoring the button to the look it had before it was pressed, not honoring the label text change. The button is conceived in IB, not programmatically.

我感觉很蠢。

推荐答案

在按钮处理程序中,尝试此

In the button handler, try this


[stopButton setTitle:@"RTN TO ZERO" forState:UIControlStateNormal];

而不是直接更改 text 属性 titleLabel 使用 setTitle:forState:方法设置标题在不同的状态。有关可用状态的详细信息,请查看手册

Instead of directly changing text property of titleLabel use setTitle:forState: method to set the title in different states. Please check the manual for the details of available states.

这篇关于UIButton上的文本更改不会阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆