2015/06/10

[iOS][Objective-C]UIButtonに画像とテキスト両方設定する

UIButtonで下のように設定しても画像とテキスト両方表示させることができなかった。

UIImage *image;
NSString *title;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
[button setTitle:title forState:UIControlStateNormal];
で、setImageではなく、
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
を使えばうまくいった。

従って最終的には、
UIImage *image;
NSString *title;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setTitle:title forState:UIControlStateNormal];

0 コメント:

コメントを投稿