2012-03-21 7 views
0

をクリックしたときにデフォルトのテキストを取得しましたが、Interface BuilderでUIButtonを作成すると、Button 1のようなテキストが表示されます。UIButtonは、

私はアプリケーションを起動したときに、私はプログラム的にこのような何か他のものにテキストを変更します。

[email protected]"Hello"; 

すべては私がボタンを押すまで、それはButton 1あるデフォルトのテキストを持ってokです。

私の目的は、テキストをプログラムで変更した場合、ボタンを押したときにデフォルトのテキスト値を取得できないということです。つまり、テキストHelloが残るはずです。どうすればいいですか?事前:)

答えて

6

でありがとうはのsetTitleを使用し、直接textLabelを変更しないでください:forState:代わりに...

See UIButton reference

3
[btn1 setTitle:@"Hello" forState:UIControlStateNormal]; 
[btn1 setTitle: @"Hello" forState: UIControlStateSelected]; 
[btn1 setTitle: @"Hello" forState: UIControlStateHighlighted]; 

・ホープ、このことができます。

2
[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];