LoginSignup
2
2

More than 5 years have passed since last update.

UIButtonのタイトルは、setTitleよりもsetAttributedTitleのほうが強い

Last updated at Posted at 2017-06-05

タイトルの通り。

例えば

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[button setAttributedTitle:@"タイトル1" forState:UIControlStateNormal];
[button setTitle:@"タイトル2" forState:UIControlStateNormal];

とすると、表示されるのは@"タイトル1" 。
@"タイトル1"と@"タイトル2"が重なって表示されるわけではなく、
あくまでsetAttributedTitleしたものしか表示されない。

だから、一度setAttributedTitleしたあとにsetTitleで文言を変えたい場合は、

[button setAttributedTitle:nil forState:UIControlStateNormal];

を忘れずに!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2