[英]How to change the color of UINavigationBar?
我想改變UINavigationBar
的顏色,顏色將從圖像中獲取。
嘗試將對象設置為navigationBar的子視圖。
設置色調顏色屬性或使用圖像
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:rootController];
controller.navigationBar.tintColor = [UIColor blackColor];
在iOS 7或更高版本中,請嘗試以下操作:
navigationBar.barTintColor = [UIColor redColor];
有一種方法可以從xcode 6.4中的storyboard中做到這一點。
從文檔大綱中選擇導航欄
比從屬性檢查器更改條紋色調
你也可以選擇其他,這將帶來顏色選擇器
選擇滴管,這將讓您從圖像中選擇一種顏色
嘗試這個:
CustomNavBar
繼承了UINavigationBar
類... MainWindow.xib
並將UINavigationBar class to
更改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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.