在iOs4
中,我使用此代码段创建了一个自定义导航栏
#import "UINavigationBar+CustomImage.h"
@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
在我的应用程序中它非常适合 ios4。现在我想在 iOs5
中运行它,问题是自定义导航栏没有按照我想要的方式显示。
谁能帮我为 iOs5
创建一个自定义导航栏。
最佳答案
您需要使用外观代理。但是,请务必检查 iOS4 是否有respondsToSelector。将您当前的方法保留在 iOS4 上,它将适用于两者。
// not supported on iOS4
UINavigationBar *navBar = [purchaseNavController navigationBar];
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
// set globablly for all UINavBars
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"brnlthr_nav.jpg"] forBarMetrics:UIBarMetricsDefault];
// could optionally set for just this navBar
//[navBar setBackgroundImage:...
}
关于iphone - 在 iOS 5 中自定义导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7793350/