2

을 숨기고 :UINavigationBar의 서브 뷰는 내가 이미지를 보유하고있는 하위 뷰를 추가 루트 테이블 뷰 컨트롤러의 오른쪽 UIBarButtonItem

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

버튼을 탐색 표시 줄에 표시되지 않는 이유는 이해할 수 없다. 탭 (공백)을 누르면 rightAction : 메서드가 호출되어 버튼이 "있으므로"표시되지 않습니다.

내비게이션 막대에서 imageView 하위보기를 보내려고했지만 아무 소용이 없습니다. 버튼이 실제로 UINavigationItem에 속하기 때문에 의미가 있습니다 ...

어떻게하면 그 버튼을 올바르게 표시 할 수 있는지 알 수 있습니까?

업데이트 :

답변

0

...에 이미지를 추가 할 수있는 더 좋은 방법을 뒤로 버튼이 제대로 표시 않지만 그래도 시스템이 추가됩니다 UINavigationBar가 서브 클래스 또는 카테고리를 확인하고 drawRect 메소드를 오버라이드 (override)하는 것입니다 :

//         #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 

이런 식으로 수행하여 버튼이 제대로 표시 될 수 적은 "해키"입니다 것입니다.

+0

UINavigationBar을 서브 클래스 할 수 있지만 속성은 UINavigationController에서 읽기 전용입니다 ... 다른 것은 "이미지"가 서버에서 실제로 검색되어 즉석에서 설정되어야한다는 것입니다. – nicktmro

+0

답변을 수락했으나 다음과 같이 입력 해 주셔서 감사합니다. navbar를 표시 할 때 이미지가 준비되지 않은 경우 검정색 배경이 나타납니다. 이미지를 사용하지 않고 기본 파란색 배경/스타일로 되돌릴 수있는 변경 사항이 있습니까? – nicktmro

+0

예, 코드를 업데이트 할 것입니다 – coneybeare

0

네비게이션 아이템의 타이틀 뷰를 imageView로 설정해야한다고 생각합니다.

self.navigationItem.titleView = imageView; 

나는 하위 뷰에 UINavigationBar 표시 UINavigationItem의 추측, 당신은 그 서브 뷰의 상단에 UIImageView를 추가했다.

내 견해 중 하나에서 레이블 옆에 이미지가 표시됩니다. 나는 labelView와 이미지 뷰를 titleView에 사용했던 뷰에 추가 한 것 같습니다.

+0

정상적으로 작동하지만 titleView는 전체 화면에 걸쳐 있지 않습니다. 나는 단지 320px가 아닌 320이라고 생각합니다. – nicktmro

+0

그런 다음 배경 이미지로 원하십니까? 좋아, 그럼 아마 인덱스 0에서 귀하의 imageView를 추가하려고 (- 삽입 서블 : atIndex :) –