2012-02-23 7 views
17

이 코드는 응용 프로그램 내에서 UINavigationBar의 색을 변경할 수 있습니다. 그러나 UINavigationController (내는 UIStoryboard에서 사용) UINavigationBarUIColor을 변경하지 않는 것으로 나타났습니다.UINavigationController 전역 및 프로그래밍 방식으로 탐색 모음 색조 색 변경

UIColor* navBarColor = [UIColor colorWithRed:arc4random()%100/100.0 
             green:arc4random()%100/100.0 
             blue:arc4random()%100/100.0 
             alpha:1]; 
[[UINavigationBar appearance] setTintColor:navBarColor]; 

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent]; 
[[UINavigationBar appearance] setAlpha:0.7]; 

UINavigationController's 탐색 모음의 appearance 개체에 액세스하는 방법이 있나요? 개별 컨트롤러의 색조를 설정하는 방법을 알고 있지만 어떻게 보일지 전체적으로 제어하려고합니다.

업데이트 : 이 내 실수는, 코드가 모든 UINavigationBarsUIColor을 변경 않습니다, 그러나 그것은 (모달 뷰 컨트롤러를 제시 예를 들어) 덮여 발견 할 수있는 루트 탐색 컨트롤러를 필요로하고이됩니다 다시 무승부 그 자체로 새로운 UIColors!

감사합니다.

답변

13

당신이 당신의 UINavigationController를 선언,이 시도 :

가 후속 실행 환경 설정을 메뉴 바의 색상을 즉시 변경하고 기억하는 완전한 솔루션을 여기에서 찾을 수 있습니다
UINavigationController *myNavController = 
[[UINavigationController alloc] initWithRootViewController:myRootViewController]; 
myNavController.navigationBar.tintColor = 
    [UIColor colorWithRed:arc4random() % 100/100.0f 
        green:arc4random() % 100/100.0f 
        blue:arc4random() % 100/100.0f 
        alpha:1.0f]; 
13

을 변경할 수

NSDictionary *textTitleOptions = 
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], 
              UITextAttributeTextColor, 
              [UIColor whiteColor], 
              UITextAttributeTextShadowColor, nil]; 

[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions]; 
textTitleOptions = 
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], 
              UITextAttributeTextColor, nil]; 
[[UINavigationBar appearance] setTintColor:[UIColor redColor]]; 
[[UIToolbar appearance] setTintColor:[UIColor redColor]]; 
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]]; 
+1

참고. – thomers

13

번호 : 바 색상이 세계적으로 appearance 프록시를 사용 아이폰 OS 8 승 우리는이에 의해 색조 색상을 설정할 수 있습니다 : - 대신`NSForegroundColorAttributeName`와`NSShadowAttributeName`를 사용 - UITextAttributeTextColor`와`UITextAttributeShadowColor`가 사용되지 않습니다`것을

self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
관련 문제