2

ルート テーブル ビュー コントローラーで、画像を保持するサブビューを追加します。

[self.navigationController.navigationBar addSubview:imageView];

次に、スタックにプッシュする子テーブル ビュー コントローラーで、適切な UIBarButtonItem を設定します。

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Right"  style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];

ナビゲーション バーにボタンが表示されない理由がわかりません。(空白スペース)をタップすると、 rightAction: メソッドが呼び出されるため、ボタンが「そこに」表示されます。表示されないことを期待してください。

imageView サブビューをナビゲーション バーに戻そうとしましたが、役に立ちませんでした。とにかくボタンが実際に UINavigationItem に属しているので、それは理にかなっています...

そのボタンを正しく表示する方法を知っている人はいますか?

更新: 戻るボタンは正しく表示されますが、システムによって追加されます...

4

2 に答える 2

0

画像をに追加するより良い方法は、画像をUINavigationBarサブクラス化するか、カテゴリを作成してdrawRectメソッドをオーバーライドすることです。

//                                  #Lighter r,g,b,a            #Darker r,g,b,a
#define MAIN_COLOR_COMPONENTS       { 0.153, 0.306, 0.553, 1.0, 0.122, 0.247, 0.482, 1.0 }
#define LIGHT_COLOR_COMPONENTS      { 0.478, 0.573, 0.725, 1.0, 0.216, 0.357, 0.584, 1.0 }

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect {
    if (imageReady) {
        UIImage *img = [UIImage imageNamed: @"navigation_background.png"];
        [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    } else {
        // Render yourself instead.
        // You will need to adjust the MAIN_COLOR_COMPONENTS and LIGHT_COLOR_COMPONENTS to match your app

       // emulate the tint colored bar
       CGContextRef context = UIGraphicsGetCurrentContext();
       CGFloat locations[2] = { 0.0, 1.0 };
       CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();

       CGFloat topComponents[8] = LIGHT_COLOR_COMPONENTS;
       CGGradientRef topGradient = CGGradientCreateWithColorComponents(myColorspace, topComponents, locations, 2);
       CGContextDrawLinearGradient(context, topGradient, CGPointMake(0, 0), CGPointMake(0,self.frame.size.height/2), 0);
       CGGradientRelease(topGradient);

       CGFloat botComponents[8] = MAIN_COLOR_COMPONENTS;
       CGGradientRef botGradient = CGGradientCreateWithColorComponents(myColorspace, botComponents, locations, 2);
       CGContextDrawLinearGradient(context, botGradient,
       CGPointMake(0,self.frame.size.height/2), CGPointMake(0, self.frame.size.height), 0);
       CGGradientRelease(botGradient);

       CGColorSpaceRelease(myColorspace);


       // top Line
       CGContextSetRGBStrokeColor(context, 1, 1, 1, 1.0);
       CGContextMoveToPoint(context, 0, 0);
       CGContextAddLineToPoint(context, self.frame.size.width, 0);
       CGContextStrokePath(context);

       // bottom line
       CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0);
       CGContextMoveToPoint(context, 0, self.frame.size.height);
       CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height);
       CGContextStrokePath(context);
    }
}

@end

このようにすると、ボタンが正しく表示され、「ハッキー」が少なくなります。

于 2009-10-28T02:36:00.857 に答える
0

ナビゲーション アイテムのタイトル ビューを imageView に設定する必要があると思います。

self.navigationItem.titleView = imageView;

UINavigationBarサブビューに s が表示されていると思いますが、そのサブビューの上にUINavigationItem追加していました。UIImageView

ビューの 1 つで、ラベルとその横に画像を表示しています。ラベルと画像ビューをビューに追加しただけで、それを titleView に使用したと思います。

于 2009-10-28T02:59:57.760 に答える