Programing

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

lottogame 2020. 4. 13. 08:08
반응형

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대신 사용하십시오 .


제목 텍스트 크기텍스트 색상 을 변경하려면 NSDictionary titleTextAttributes 를 2 개의 객체 로 변경해야 합니다.

    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:13.0],NSFontAttributeName,
                                                                  [UIColor whiteColor], NSForegroundColorAttributeName, 
                                                                  nil];

이전 답변이 맞다고 생각합니다. 이것은 동일한 일을하는 또 다른 방법입니다. 누군가에게 유용 할 경우를 대비하여 다른 사람들과 공유하고 있습니다. ios7에서 탐색 표시 줄의 텍스트 / 제목 색상을 변경하는 방법은 다음과 같습니다.

UIColor *red = [UIColor colorWithRed:254.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0];
NSMutableDictionary *navBarTextAttributes = [NSMutableDictionary dictionaryWithCapacity:1];
[navBarTextAttributes setObject:red forKey:NSForegroundColorAttributeName ];
self.navigationController.navigationBar.titleTextAttributes = navBarTextAttributes;

탐색 막대 버튼에 대해 색상별로 수행하려는 모든 것을 재정의의 Accessibility컨트롤이 iOS Settings거의 사용 하는 것 같습니다 . 모든 설정을 기본 위치 (증가 대비, 굵은 체 텍스트 , 단추 모양 등 끄기)로 설정해야합니다. 그렇지 않으면 아무 것도 변경되지 않습니다. 일단 그렇게하면 모든 색상 변경 코드가 예상대로 작동하기 시작했습니다. 모두 해제 할 필요는 없지만 더 이상 추구하지는 않았습니다.

참고 URL : https://stackoverflow.com/questions/19029833/ios-7-navigation-bar-text-and-arrow-color

반응형