8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

iOSの拡張キーボードに設定したUIToolbarの色を合わせる方法

拙作のArrow NoteではinputAccessoryViewにUIToolbarを使っています。これはボタンを配置するのが楽ちんなのですが、iOS7になってキーボードに色を合わせるのに苦労しました。というのも、UIToolbarはtintとかいうエフェクトが掛かって、単にキーボードと同じ色に設定しても駄目なのです。というわけで、試行錯誤した結果を共有いたします。
(iOS7.1で色が変わったので修正しました)

ObjectiveC
@interface ViewController : UIViewController
@property IBOutlet UITextView *textView;
@end

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    if (self.textView.keyboardAppearance == UIKeyboardAppearanceAlert) {
        toolBar.barTintColor = [UIColor colorWithWhite:0.246 alpha:1];
    }
    else {
        toolBar.barTintColor = [UIColor colorWithRed:0.797 green:0.812 blue:0.840 alpha:1.000];
    }
    self.textView.inputAccessoryView = toolBar;
}
@end

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
Sign upLogin
8
Help us understand the problem. What are the problem?