@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"title.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
}
@end
@implementation HXNavigationController
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self) {
#if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 5.0)
{
if ([self.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"title.png"] forBarMetrics:UIBarMetricsDefault];
}
}
#endif
}
return self;
}自定义navigation bar 支持iOS5以及iOS5以下版本的代码
最新推荐文章于 2026-06-21 09:13:29 发布
本文介绍了一种在iOS应用中自定义UINavigationBar背景的方法,通过重写drawRect方法或使用setBackgroundImage方法来实现定制化的导航栏外观。
2377

被折叠的 条评论
为什么被折叠?



