UIButtonのラベルを変更できない


以下のソースコードでは、UIButtonのタイトルは正しく設定できません。

UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(10.0f, 120.0f, 300.0f, 50.0f);
button.titleLabel.text = @"ボタン名";

UIButtonのタイトルはsetTitle:forState:を使って書き換えます。

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(10.0f, 120.0f, 300.0f, 50.0f);
[button setTitle:@"ボタン名" forState:UIControlStateNormal];

Comments

comments

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です