2012-02-09 61 views
2

我想更改UINavigationBar的顏色,顏色將從圖像中獲取。如何更改UINavigationBar的顏色?

+0

您wanrt改變顏色或使用圖像 – Deepesh 2012-02-09 06:02:47

+0

我想改變UINavigationBar的背景下,我使用colorWithImagePattern,但其沒有工作 – Ali 2012-02-09 06:04:08

回答

6

嘗試將對象設置爲navigationBar的子視圖。

設置着色顏色屬性或使用圖像

UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:rootController]; 
controller.navigationBar.tintColor = [UIColor blackColor]; 
+1

感謝的人妳太美好了。 – NaXir 2013-08-13 05:16:42

0

試試這個:

  1. 首先創建目標C類說CustomNavBar繼承UINavigationBar類...
  2. 然後導入這個類你的appDelegate ...
  3. 然後將下面的代碼放在你的appDelegate類的末尾...
  4. 然後打開MainWindow.xib並更改UINavigationBar class to CustomNavBar`。

代碼:

@implementation CustomNavBar (CustomNavBarCategory) 

-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 
{ 

    if([self isMemberOfClass:[CustomNavBar class]]) 
    { 
     UIImage *image; 

     image=[UIImage imageNamed:@"ImageName"]; 

     CGContextClip(ctx); 
     CGContextTranslateCTM(ctx, 0, image.size.height); 
     CGContextScaleCTM(ctx, 1.0, -1.0); 
     CGContextDrawImage(ctx,CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage); 

    } 
    else 
    {   
     [super.layer drawLayer:layer inContext:ctx];  
    } 

} 

@end 
2

在iOS 7以上版本,請嘗試以下操作:

navigationBar.barTintColor = [UIColor redColor]; 
0

有一種方法可以在Xcode 6.4要做到這一點從情節串連圖板。

從文檔大綱選擇導航條

不是從屬性檢查器中改變杆色調

您也可以選擇其他的,這會帶來顏色選擇器

選擇滴管,這將讓你從圖像中選擇一種顏色

相關問題