Iphone 在iOS 5中自定义导航栏
在Iphone 在iOS 5中自定义导航栏,iphone,ipad,ios4,uinavigationbar,ios5,Iphone,Ipad,Ios4,Uinavigationbar,Ios5,在iOs4中,我使用此代码段创建了一个自定义导航栏 #import "UINavigationBar+CustomImage.h" @implementation UINavigationBar (CustomImage) - (void)drawRect:(CGRect)rect { // Drawing code UIImage *image = [[UIImage imageNamed:@"header.png"] retain]; [image drawIn
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的选择器。将当前方法保留在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:...
}
这里提到了相同的问题:。请检查此选项,这可能会对您有所帮助。只需将以下代码放入应用程序委托,即使在ios5中,它也可以正常工作
我把它放进去了
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// Create image for navigation background - portrait
UIImage *NavigationPortraitBackground = [[UIImage imageNamed:@"NavigationPortraitBackground"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Create image for navigation background - landscape
UIImage *NavigationLandscapeBackground = [[UIImage imageNamed:@"NavigationLandscapeBackground"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set the background image all UINavigationBars
[[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:NavigationLandscapeBackground
forBarMetrics:UIBarMetricsLandscapePhone];
检查iOS版本并设置导航栏图像
如果([[[UIDevice currentDevice]systemVersion]floatValue]