IOS 5 自定义导航条背景图片
生活随笔
收集整理的這篇文章主要介紹了
IOS 5 自定义导航条背景图片
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
IOS 4的時候:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
// Drawing code
UIImage *image = [[UIImage imageNamed:@"header.png"] retain];
[image drawInRect:CGRectMake(0, 0,self.frame.size.width , self.frame.size.height)];
[image release];
}
@end
IOS 5以上的代碼不會被調(diào)用到,上面代碼依舊使用,然后加一句以下代碼到你的程序委托中: if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar_nav.jpg"] forBarMetrics:UIBarMetricsDefault];? } 這樣就支持2種版本了,還有其他方法,比如建個子類。
- (void)drawRect:(CGRect)rect {
// Drawing code
UIImage *image = [[UIImage imageNamed:@"header.png"] retain];
[image drawInRect:CGRectMake(0, 0,self.frame.size.width , self.frame.size.height)];
[image release];
}
@end
IOS 5以上的代碼不會被調(diào)用到,上面代碼依舊使用,然后加一句以下代碼到你的程序委托中: if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar_nav.jpg"] forBarMetrics:UIBarMetricsDefault];? } 這樣就支持2種版本了,還有其他方法,比如建個子類。
總結(jié)
以上是生活随笔為你收集整理的IOS 5 自定义导航条背景图片的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 排序算法之希尔排序(Java实现)
- 下一篇: 跨站点请求伪造(CSRF)