您的位置:首页 > 移动开发 > IOS开发

IOS 5 自定义导航条背景图片

2011-11-08 01:23 501 查看
IOS 4的时候:
@implementation UINavigationBar (CustomImage)- (void)drawRect:(CGRect)rect {// Drawing codeUIImage *image = [[UIImage imageNamed:@"header.png"] retain];[image drawInRect:CGRectMake(0, 0,self.frame.size.width , self.frame.size.height)];[image release];}@end
IOS 5以上的代码不会被调用到,上面代码依旧使用,然后加一句以下代码到你的程序委托中:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar_nav.jpg"] forBarMetrics:UIBarMetricsDefault];}
这样就支持2种版本了,还有其他方法,比如建个子类。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: