従来のiOSではNavigationBarに色を指定する場合、tintColorプロパティを使用していたが、iOS7ではbarTintColorプロパティを使用する。
barTintColorでバーの背景の色遣いを設定
self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
tintColorでバーボタンの色遣いを設定
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
いずれもviewWillAppearメソッドで設定すること。viewDidLoadメソッドで実行してもNavigationBarのプロパティには反映されない。
(例)バーボタンの色遣いの設定について、iOS7以降を対象とする場合のコード。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
// iOS 7.0以降
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
}
}
また、windowにtintColorプロパティを指定すると、アプリケーション全体に適用する色を設定できる。
この設定は、NavigationBarに表示するテキスト・ボタン、TabBarのテキスト、UITableViewCellのaccessoryTypeプロパティなどに及ぶ。
window.tintColor = [UIColor greenColor];
アプリケーション全体にNavigationbarの色を指定する場合は、下記のようにAppDelegete.mで指定する。
[UINavigationBar appearance].barTintColor = [UIColor greenColor];
アプリケーション全体にNavigationbarのタイトル文字色を指定する場合は、下記のようにAppDelegete.mで指定する。
[UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithRed:(225.0f/255.0f) green: (94.0f/255.0f) blue:(173.0f/255.0f) alpha:1.0f]};
参考記事:
https://developer.apple.com/jp/devcenter/ios/library/documentation/UserExperience/Conceptual/TransitionGuide/AppearanceCustomization/AppearanceCustomization.html#//apple_ref/doc/uid/TP40013174-CH15-SW1
【UIColorの最新記事】