これはシモーヌの答えと同じラインに沿っているが、iOSの5とiOSのために働く< 5.これが私がアプリで使っているものです。アプリの初期化のどこかで[UINavigationBar setupIos5PlusNavBarImage]
に電話する必要があります(applicationDidFinishLaunching:は良い候補です)。 iOS 5以降では、setupIos5PlusNavBarImageは新しいUIAppearanceプロトコルを使用して背景を設定し、drawRectオーバーライドは無視されます。 iOS <では、setupIos5PlusNavBarImageは基本的にノーオペレーションになり、drawRectはイメージの描画を処理します。
インタフェース:
@interface UINavigationBar (CustomNavigationBar)
+ (void) setupIos5PlusNavBarImage;
- (void) drawRect: (CGRect) rect;
@end
実装:
@implementation UINavigationBar (CustomNavigationBar)
+ (void) setupIos5PlusNavBarImage
{
if ([UINavigationBar respondsToSelector: @selector(appearance)])
{
[[UINavigationBar appearance] setBackgroundImage: [UIImage imageNamed: @"menuBar.png"] forBarMetrics: UIBarMetricsDefault];
}
}
- (void) drawRect: (CGRect) rect
{
UIImage* img = [UIImage imageNamed: @"menuBar.png"];
[img drawInRect: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
iOS5をので、私はあなたがAppleの専用フォーラム上のポインタのための唯一の – Vladimir