[iphone] iOS 7 탐색 막대 텍스트 및 화살표 색

탐색 표시 줄의 배경을 검은 색으로 설정 하고 그 안의 모든 색상을 흰색 으로 설정하고 싶습니다 .

그래서 나는이 코드를 사용했다 :

[[UINavigationBar appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor whiteColor],
      NSForegroundColorAttributeName,
      [UIColor whiteColor],
      NSForegroundColorAttributeName,
      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
      NSForegroundColorAttributeName,
      [UIFont fontWithName:@"Arial-Bold" size:0.0],
      NSFontAttributeName,
      nil]];

그러나 뒤로 단추 텍스트 색 , 화살표막대 단추 는 여전히 기본적으로 파란색입니다 .
아래 이미지와 같이 색상을 변경하는 방법은 무엇입니까?

여기에 이미지 설명을 입력하십시오



답변

일부 속성의 동작 UINavigationBariOS 7 에서 변경되었습니다 . 아래 이미지에서 볼 수 있습니다.

여기에 이미지 설명을 입력하십시오


당신과 공유하고 싶은 두 개의 아름다운 링크. 자세한 내용은 다음 링크를 통해 확인할 수 있습니다.

  1. iOS 7 UI 전환 안내서 .
  2. iOS 7 용 앱을 업데이트하는 방법 .

barTintColor에 대한 Apple 설명서 는 다음 과 같이 말합니다.

반투명 속성을 NO로 설정하지 않으면이 색상은 기본적으로 반투명합니다.

샘플 코드 :

self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;


답변

여기에 이미지 설명을 입력하십시오

이것은 나를 알아내는 데 반나절 정도 걸렸지 만 이것이 나를 위해 일한 것입니다. navigationController를 초기화하는 rootViewController 내부에서이 코드를 viewDidAppear 메소드에 넣습니다.

//set bar color
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];
//optional, i don't want my bar to be translucent
[self.navigationController.navigationBar setTranslucent:NO];
//set title and title color
[self.navigationItem setTitle:@"Title"];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];
//set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
//set back button arrow color
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

여기 에 내 전체 게시물


답변

스위프트 3, iOS 10

AppDelegate에서 색상을 전체적으로 지정하려면 didFinishLaunchingWithOptions다음을 수행하십시오.

let textAttributes = [NSForegroundColorAttributeName:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes

스위프트 4, iOS 11

let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes


답변

Vin의 대답은 저에게 효과적이었습니다. Xamarin.iOS / MonoTouch를 사용하는 C # 개발자를위한 동일한 솔루션은 다음과 같습니다.

var navigationBar = NavigationController.NavigationBar; //or another reference
navigationBar.BarTintColor = UIColor.Blue;
navigationBar.TintColor = UIColor.White;
navigationBar.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White });
navigationBar.Translucent = false;


답변

스위프트 / iOS8

let textAttributes = NSMutableDictionary(capacity:1)
textAttributes.setObject(UIColor.whiteColor(), forKey: NSForegroundColorAttributeName)
navigationController?.navigationBar.titleTextAttributes = textAttributes


답변

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];


답변

UINavigationBar제목 색상을 올바른 방법으로 변경하려면 다음 코드를 사용하십시오.

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];

UITextAttributeTextColor최신 iOS 7 버전에서는 더 이상 사용되지 않습니다. NSForegroundColorAttributeName대신 사용하십시오 .