2013/05/15

[iOS][Objective-C]UIButtonのテキストが表示されない件

UIButtonに以下のようにテキストを設定してもなぜか表示されない。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.text = @"ButtonTitle";
どうやらテキストの設定は、
- (void)setTitle:(NSString *)title forState:(UIControlState)state
を使わないといけないようだ。
従って最終的には以下のプログラムで落ち着く
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"ButtonTitle" forState:UIControlStateNormal];
これからボタンにテキストを設定するときは気をつけないとな。

0 コメント:

コメントを投稿