2013-09-21 73 views
1

我有我的iOS應用程序和iOS 6自定義主題,它看起來像我想要的。 但是,在iOS 7上,操作系統會自動使背景(以及我用作按鈕的圖像)變暗,因此看起來不同。iOS 7酒吧按鈕項目:自定義背景圖像和突出顯示狀態變暗圖像

所以我有一個自定義圖像欄按鈕項目,下面的代碼:

UIImage *navbarButton = [[UIImage imageNamed:@"navbar_button"] 
         resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)]; 
UIImage *navbarButtonHighlight = [[UIImage imageNamed:@"navbar_button_highlight"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)]; 
[[UIBarButtonItem appearance] setBackgroundImage:navbarButton 
             forState:UIControlStateNormal 
             barMetrics:UIBarMetricsDefault]; 
[[UIBarButtonItem appearance] setBackgroundImage:navbarButtonHighlight 
             forState:UIControlStateHighlighted 
             barMetrics:UIBarMetricsDefault]; 
[[UIBarButtonItem appearance] setBackgroundImage:navbarButtonHighlight 
             forState:UIControlStateSelected 
             barMetrics:UIBarMetricsDefault]; 

我在做什麼錯了/忘了?

回答

1
if([Utilities iOSVersion] >= 7){ 

    [self.navigationController.navigationBar setBarTintColor:[UIColor whateverColorYouWant]]; 

    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; 

    //translucent is key 

    self.navigationController.navigationBar.translucent = NO; 
} 


/** 
* @return this device OS version 
*/ 
+(int)iOSVersion{ 

    NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; 

    return [[ver objectAtIndex:0]intValue]; 
} 
+0

感謝這確實有效! – nickygerritsen

0

試着做[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]。我有類似的問題,這讓它變得更加輕鬆。

+0

不,僅改變在條項目的圖標(我已經有一個'self.window.tintColor = [的UIColor whiteColor];') – nickygerritsen

+0

糟糕我的意思bakcgroundcolor。對不起,我不記得完全一樣,因爲我現在無法訪問我的文件 – user1529956

+0

我只在導航欄上看到'barTintColor'和'tintColor',它們都不起作用。 – nickygerritsen

相關問題