Simple gadget life programming diary

Simple gadget life の中の人によるプログラミングメモ

UInavigationBarの色の変更とオリジナルボタンの設定

こんな事が出来る

f:id:jtaka1012:20131121215526j:plain

やり方

色の変更

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.498 green:0.275 blue:0.718 alpha:1.0];

ちなみにツールバーの色の変更はこんな感じ

UIToolbar *_toolbar;

_toolbar.tintColor = [UIColor colorWithRed:0.498 green:0.275 blue:0.718 alpha:1.0];

オリジナルのボタンをナビゲーションバーに配置する

#import "ionicons.h" //フォントアイコンのライブラリ

    UIImage *images = [IonIcons imageWithIcon:icon_images
                                    iconColor: [UIColor colorWithRed:0.498 green:0.275 blue:0.718 alpha:1.0]
                                     iconSize:30.0f
                                    imageSize:CGSizeMake(30.0f, 30.0f)];

    UIBarButtonItem *btn =
    [[UIBarButtonItem alloc]
     initWithImage:images  // 画像を指定
     style:UIBarButtonItemStylePlain  // スタイルを指定(※下記表参照)
     target:self  // デリゲートのターゲットを指定
     action:@selector(rightFieldButtonPushed)  // ボタンが押されたときに呼ばれるメソッドを指定
     ];

    self.navigationItem.rightBarButtonItem = btn;

注意点

ナビゲーションバーにくっつけるボタンはUIBarButtonItemにする必要がある。 UIButtonはNG。