iphone - 在 iOS 5 中自定义导航栏

标签 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 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/

相关文章:

iphone - 如何快速访问Xcode 4.5.1中的文档?

ios - 可以在 iPad 上编辑 Firebase Cloud Functions 并部署更改吗?

ios - 'NSInvalidUnarchiveOperationException',原因 : 'Could not instantiate class named UIStoryboardPresentationSegueTemplate'

iphone - 使用 UISegmentedControl 作为按钮

ios - UILabel textColor 在 iOS 4.3 中没有正确设置

ios - 在歌曲加载时,如果用户使用 AVAudioplayer 单击 iPhone 中的播放按钮,如何显示事件指示器

iphone - iOS 应用内购买分步教程

iphone - 如何为我的 View 添加动画效果?

iphone - 使用 Mapkit 确定距离

c# - 如何在 iPhone/iTouch 上运行 XNA 制作的游戏?