UIButtonのタイトルの色を変更するにはどうすればよいですか? 質問する

UIButtonのタイトルの色を変更するにはどうすればよいですか? 質問する

プログラムでボタンを作成します..........

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];

タイトルの色を変更するにはどうすればよいですか?

ベストアンサー1

これを行うには、 を使用できます-[UIButton setTitleColor:forState:]

例:

オブジェクティブC

[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

スイフト2

buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)

スイフト3

buttonName.setTitleColor(UIColor.white, for: .normal)

感謝リチャード・チャイルダン

おすすめ記事