アプリで 2 つの UINavigationBar を使用しています。現在、アプリにテーマを適用しています。このコード行を使用して、アプリ全体のナビゲーション バーの色を変更しようとしています。
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
黒い色の 2 つのナビゲーション バーが表示されます アプリ全体で 1 つのナビゲーション バーの色を変更する方法はありますか
アプリで 2 つの UINavigationBar を使用しています。現在、アプリにテーマを適用しています。このコード行を使用して、アプリ全体のナビゲーション バーの色を変更しようとしています。
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
黒い色の 2 つのナビゲーション バーが表示されます アプリ全体で 1 つのナビゲーション バーの色を変更する方法はありますか
代わりに、コンテキストに基づいてどの UINavigationBars が変更されるかをより具体的に示すために[UINavigationBar appearance]
使用できます。[UINavigationBar appearanceWhenContainedIn:...]
たとえば、UINavigationController
calledのサブクラスを作成してMyNavigationController
(動作を追加する必要はありません)、次のようにします。
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationController class], nil] setTintColor:[UIColor blackColor]];
サブクラス内に存在する UINavigationBars のみ、外観が変更されます。
たとえば、モーダル FormSheets 内に表示される UINavigationBars が、アプリ内の他の UINavigationBars とは異なるように見えるようにしたい iPad アプリでこのアイデアを使用しました。
すべてのナビゲーションバーの色を変更するには、メソッドを使用できます
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
全体的なフォントなどを変更するには、次のようなものを使用できます。
-(void) changeNavigationBarStyle{
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"ChalkboardSE-Bold" size:0.0],
UITextAttributeFont,
nil]];
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:@"ChalkboardSE-Bold" size:0.0f] forKey:UITextAttributeFont];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
コメントによる編集
アプリケーション内のすべての UINavigationBars の色 (この例では青) を変更するには、呼び出すことができます
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
UINavigationBar の色を変更するには、呼び出すことができます
self.navigationController.navigationBar.tintColor = [UIColor blueColor];
「... を除くすべての UINavigationBar の色を変更する」と言える妥協点はありません。
ナビゲーションバーに使用したい色の画像を入れたい場合
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] )
{
UIImage *image = [UIImage imageNamed:@"titlebg.png"] ;
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
それ以外の場合は、使用して色合いを簡単に設定できます
[navigationController.navigationBar setTintColor:[UIColor colorWithRed:102/255.00f green:182/255.00f blue:114/255.00f alpha:1.0f]];
お役に立てれば。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if(isiPhone5)
{
self.LoadinFirst = [[LoadingFirstViewController alloc] initWithNibName:@"LoadingFirstView-iPhone5" bundle:nil];
}
else {
self.LoadinFirst = [[LoadingFirstViewController alloc] initWithNibName:@"LoadingFirstView" bundle:nil];
}
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.LoadinFirst];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor colorWithRed:192/255.00f green:182/255.00f blue:184/255.00f alpha:1.0f]];
self.window.rootViewController =navigationController;
[self.window makeKeyAndVisible];
return YES;
}