문제

루트 테이블 뷰 컨트롤러에서 이미지를 보유하는 하위 뷰를 추가합니다.

[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];

탐색 표시 줄에 버튼이 표시되지 않는 이유를 이해할 수 없습니다. (빈 공간)를 누르면 오른쪽 요소 : 메소드가 호출되어 버튼이 "거기에"표시되지 않도록 기대합니다.

ImageView 하위 뷰를 내비게이션 바에서 다시 보내려고했지만 아무 소용이 없습니다. 버튼이 실제로 UinavigationItem에 속해 있기 때문에 그것은 의미가 있습니다 ...

내가 어떻게 해당 버튼을 올바르게 표시 할 수 있는지 아는 사람이 있습니까?

업데이트 : 뒤로 버튼이 올바르게 표시되지만 시스템에서 추가됩니다 ...

도움이 되었습니까?

해결책

이미지를 추가하는 더 좋은 방법 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

이렇게하면 버튼이 올바르게 표시되고 "해킹"이 적습니다.

다른 팁

내비게이션 항목의 제목보기를 ImageView로 설정해야한다고 생각합니다.

self.navigationItem.titleView = imageView;

나는 UINavigationBar 표시합니다 UINavigationItems 하위 뷰에 있고 당신은 당신의 UIImageView 그 하위 뷰 외에.

내 견해 중 하나에서 나는 그 옆에 레이블과 이미지를 표시하고 있습니다. 방금 TitleView에 사용한 뷰에 레이블과 이미지보기를 추가했다고 생각합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top