2011-12-20 3 views
-1

私は、xcode 4(ios 4.3)を使用してプロジェクトでカスタマイズされたナビゲーションとツールバーを実装していますが、ここでは動作しません。ここでは、この1ナビゲーションとツールバーカスタマイズされた背景イメージがIOSで動作していません5

に助けてください奇妙なことにする事が私のアプリのデリゲートコードを使用すると、UINavigationBarのサブクラスを作成し、そこのdrawRectを呼び出すまでdrawLayerかのdrawRectメソッドが呼び出されることはありません

@implementation UINavigationBar (CustomImage) 
- (void)drawRect:(CGRect)rect { 
    UIImage *image = [UIImage imageNamed: @"TopBg_with_logo.png"]; 
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 
@end 

@implementation UIToolbar (CustomImage) 
- (void)drawRect:(CGRect)rect { 
    UIImage *image = [UIImage imageNamed: @"btmbar_Bg.png"]; 
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 
@end 

答えて

1

です。

このコードをたどる -

@implementation UINavigationBar (UINavigationBarCategory) 

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 
{ 




     if([self isMemberOfClass:[UINavigationBar class]]) 
     { 
      UIImage *image; 


      image=[UIImage imageNamed:@"title_768.png"]; 



      CGContextClip(ctx); 
      CGContextTranslateCTM(ctx, 0, image.size.height); 
      CGContextScaleCTM(ctx, 1.0, -1.0); 
      CGContextDrawImage(ctx, 
           CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage); 


     } 
     else 
     {   
      [super drawLayer:layer inContext:ctx];  
     } 

} 
@end 

そして、あなたのコード内でMyNavigationBar.hとMyNavigationBar.mファイルを追加 -

MyNavigationBar.h -

#import <Foundation/Foundation.h> 

@interface MyNavigationBar : UINavigationBar <UINavigationBarDelegate> 

@end 

MyNavigationBar.m -

#import "MyNavigationBar.h" 

@implementation MyNavigationBar 

- (id)initWithFrame:(CGRect)frame { 
    if (self = [super initWithFrame:frame]) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect 
{ 



    UIImage *image; 

    image=[UIImage imageNamed:@"title_768.png"]; 


    [image drawInRect: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) ]; 


} 

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 

} 

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
} 


@end 

そして、あなたのUINavigationBarをMyNavigationBarでサブクラス化してください。その場合、使用中の

0

このコード:

float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (version >= 5.0) { 
     UINavigationBar *navBar = self.navigationController.navigationBar; 
     UIImage *image = [UIImage imageNamed:@"topbar.png"]; 
     [navBar setBackgroundImage:image forBarMetrics:UIBarStyleDefault]; 
    } 
関連する問題