转自:http://blog.liming.it/?p=272

 

1、自定义背景色

// 设置 navigationbar 颜色
self.navigationController.navigationBar.tintColor = [UIColor redColor];

2、设置为图片
// 设置 navigationbar 背景图
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"weibologo.png"] forBarMetrics:UIBarMetricsDefault];

iOS 4 下设置背景图
在 AppDelegate 参考如下代码 (放在头部 #import 和 @implementation AppDelegate 之间):
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"top_bar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

3、全透明
self.navigationController.navigationBar.translucent = YES;
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *maskedImage = [UIImage imageWithCGImage:CGImageCreateWithMaskingColors([[UIImage alloc]init].CGImage, colorMask)];
[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];

4、半透明
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.alpha = 0.8;

5、顺便让 StatusBar 也半透明了:
self.navigationController.navigationBar.translucent = YES;
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
self.wantsFullScreenLayout = YES;

6、设置 title 的文字颜色:
NSDictionary *navTitleArr = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:20],UITextAttributeFont,
[UIColor redColor],UITextAttributeTextColor ,
[NSValue valueWithCGSize:CGSizeMake(2.0, 2.0)] , UITextAttributeTextShadowOffset ,
[UIColor whiteColor] ,UITextAttributeTextShadowColor ,
nil];
[navBar setTitleTextAttributes:navTitleArr];

参考资料:
自定义UINavigationBar的背景
Custom UINavigationBar: Two Techniques
华山论剑 — 自定义UINavigationBar背景方法汇总
User Interface Customization in iOS 6
裝扮UINavigationBar的美麗容顏
IOS之UINavigationBar

posted on 2014-05-15 11:39  М80メ  阅读(268)  评论(0编辑  收藏  举报