2013-05-16 31 views
0

我已經用兩個UINavigationBar的在我的應用程序,現在正在申請的主題,我的應用我試圖使用此行代碼來改變總的應用程序的導航欄的顏色更改單個導航欄的顏色總應用

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; 

我得到與黑色兩個導航欄有沒有辦法來改變單一的導航欄的顏色總應用

回答

0

要更改過的所有導航欄的顏色,你可以使用的方法

[[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]; 

} 

編輯DUE TO評論
改變所有UINavigationBars的顏色(藍色在這個例子中)的應用程序可以調用

[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]]; 

要改變一個UINavigationBar的顏色,你可以調用

self.navigationController.navigationBar.tintColor = [UIColor blueColor]; 

沒有中間地帶,你可以說「更改所有UINavigationBar的的顏色,除了......」

+0

我有2個導航條,使用上述2導航欄顏色變化我想改變只有一個導航欄的顏色,使用的appdelegate文件 – user2197875

+1

你有一個的viewController兩個導航欄? – iEinstein

+0

是@Ashutosh Mishra – user2197875

0
- (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; 
} 
+0

現在你可以改變所有的導航欄顏色 – hitesh

+0

我有2個導航欄,使用上面的2個導航欄顏色正在改變我想改變只有一個導航欄顏色,使用appdelegate文件 – user2197875

+0

你把setTintColor代碼的代碼,並改變導航欄的顏色..... – hitesh

0

如果你想要把圖像與你願意,你可以使用

色導航欄
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) 
    { 
     UIImage *image = [UIImage imageNamed:@"titlebg.png"] ; 
     [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 
    } 

其他你能easilt使用

[navigationController.navigationBar setTintColor:[UIColor colorWithRed:102/255.00f green:182/255.00f blue:114/255.00f alpha:1.0f]]; 

希望這有助於設定的色調。

+0

我有2個導航欄,使用上面的2個導航欄顏色正在改變我想改變只有一個導航欄的顏色,使用appdelegate文件 – user2197875

+0

你能告訴我兩個導航欄的要求 – iEinstein

1

而不是[UINavigationBar appearance]您可以使用[UINavigationBar appearanceWhenContainedIn:...]更具體地關於哪些UINavigationBar根據其上下文更改。

例如,你可以創建UINavigationController一個子類,稱爲MyNavigationController(無需添加任何行爲),然後執行:

[[UINavigationBar appearanceWhenContainedIn:[MyNavigationController class], nil] setTintColor:[UIColor blackColor]]; 

住你的子類中,將有他們的出現改變了只有UINavigationBars。

我在iPad應用程序,我想UINavigationBars出現模式FormSheets內尋找到應用程序,例如內的其他UINavigationBars不同使用這種想法。