Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIButton在单击时获得默认文本_Objective C_Ios_Uibutton - Fatal编程技术网

Objective c UIButton在单击时获得默认文本

Objective c UIButton在单击时获得默认文本,objective-c,ios,uibutton,Objective C,Ios,Uibutton,当我在Interface builder上创建UIButton时,我放置了一个类似于按钮1的文本 启动应用程序时,我会以编程方式将文本更改为以下内容: btn1.titleLabel.text=@"Hello"; 在我按下按钮之前,一切都正常,它得到了默认文本,即按钮1 我的目的是,如果文本以编程方式更改,当我按下按钮时,它无法获得其默认文本值,我的意思是文本Hello应该保留。请问我怎么做?Thanx prevance:)不要直接更改文本标签,请使用setTitle:forState:代替

当我在Interface builder上创建UIButton时,我放置了一个类似于
按钮1
的文本

启动应用程序时,我会以编程方式将文本更改为以下内容:

btn1.titleLabel.text=@"Hello";
在我按下按钮之前,一切都正常,它得到了默认文本,即
按钮1


我的目的是,如果文本以编程方式更改,当我按下按钮时,它无法获得其默认文本值,我的意思是文本
Hello
应该保留。请问我怎么做?Thanx prevance:)

不要直接更改文本标签,请使用setTitle:forState:代替

希望这有帮助

[myButton setTitle: @"myTitle" forState: UIControlStateNormal];

use  UIControlStateNormal to set your title.

there are couple of states that UIbuttons provide, you can have a look:

[myButton setTitle: @"myTitle" forState: UIControlStateApplication];
[myButton setTitle: @"myTitle" forState: UIControlStateHighlighted];
[myButton setTitle: @"myTitle" forState: UIControlStateReserved];
[myButton setTitle: @"myTitle" forState: UIControlStateSelected];
[myButton setTitle: @"myTitle" forState: UIControlStateDisabled];
[myButton setTitle: @"myTitle" forState: UIControlStateNormal];

use  UIControlStateNormal to set your title.

there are couple of states that UIbuttons provide, you can have a look:

[myButton setTitle: @"myTitle" forState: UIControlStateApplication];
[myButton setTitle: @"myTitle" forState: UIControlStateHighlighted];
[myButton setTitle: @"myTitle" forState: UIControlStateReserved];
[myButton setTitle: @"myTitle" forState: UIControlStateSelected];
[myButton setTitle: @"myTitle" forState: UIControlStateDisabled];