Help us understand the problem. What is going on with this article?

【Obj-C】UIButtonの文字色をtintColorで変更しても白のままになってしまう

More than 3 years have passed since last update.

背景

UIButtonの文字色を変更する際は、以下のように
button.tintColor = [UIColor redColor];
と指定するが、なぜかどれだけ設定しても色が「白色」のまま変更できなかった。

解決

UIButtonに対してbuttonWithTypeの設定をし忘れておりました。Obj-Cに慣れてきてサラで書くようになると案外忘れがちになるかも。

コード

button = [[UIButton alloc]initWithFrame:CGRectMake(x,y,width,height)];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //コレ
button.titleLabel.font = [UIFont boldSystemFontOfSize:15];
[button setTitle:@"hoge" forState:UIControlStateNormal];
button.tintColor = [UIColor redColor];
asa_s
Unity Engineer (2016 - now), Scala Engineer (2016 - now), iOS Engineer (2014 - 2016)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした