1

Xcode 4.3.2 を使用し、「Master-Detail Application」テンプレートに基づいて空のプロジェクトを作成します。以下のコードでデフォルトのナビゲーション バーの外観を変更しようとしても、何も起こらず、drawRect 関数が呼び出されません。

#import "AppDelegate.h"

@implementation UINavigationBar (UINavigationBarCustomDraw)

- (void)drawRect:(CGRect)rect
{
    NSLog(@"redraw");
    [[UIImage imageNamed:@"NavBar.png"] drawInRect:rect];
    self.topItem.titleView = [[UIView alloc] init];

    self.tintColor = [UIColor colorWithRed:0.6745098 green:0.6745098 blue:0.6745098 alpha:1.0];
 }

 @end

 @implementation AppDelegate
 ...  

iOS 5.x では、ユーザーはより簡単な方法で UI の外観を変更できることを知っています。

[[UINavigationBar appearance] setBackgroundImage:img 
                                   forBarMetrics:UIBarMetricsDefault];

しかし、なぜ drawRect が呼び出されないのだろうか、誰でも説明できますか?

4

0 に答える 0