development

탐색 모음의 글꼴 변경

big-blog 2020. 11. 19. 21:45
반응형

탐색 모음의 글꼴 변경


질문은 간단하고 간단하지만 안타깝게도 대답은 아닙니다.

에서 텍스트의 글꼴을 어떻게 변경할 수 UINavigationBar있습니까?


iOS 7 이상 :

NSShadow* shadow = [NSShadow new];
shadow.shadowOffset = CGSizeMake(0.0f, 1.0f);
shadow.shadowColor = [UIColor redColor];
[[UINavigationBar appearance] setTitleTextAttributes: @{
     NSForegroundColorAttributeName: [UIColor greenColor],
                NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20.0f],
              NSShadowAttributeName: shadow
                                                      }];

iOS 5 이상 :

 [[UINavigationBar appearance] setTitleTextAttributes: @{
                                UITextAttributeTextColor: [UIColor greenColor],
                          UITextAttributeTextShadowColor: [UIColor redColor],
                         UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                     UITextAttributeFont: [UIFont fontWithName:@"Helvetica" size:20.0f]
     }];

iOS 5 이전 :

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor whiteColor];
label.text=self.title;  
self.navigationItem.titleView = label;      
[label release];

Interface Builder 자체에서 (코드없이) 글꼴을 변경하려면 Xcode6에서 수행하는 방법이 있습니다.

1.) 탐색 컨트롤러 장면에서 탐색 모음보기를 찾습니다. 여기에 이미지 설명 입력

2.) Attributes Inspector에서 Title Font, Color 및 Shadow 속성을 변경합니다. 여기에 이미지 설명 입력


위의 답변이 작동합니다. 마지막 줄 앞에 다음 줄을 추가합니다. 그렇지 않으면 왼쪽에 뒤로 버튼이 있지만 오른쪽 버튼이 없으면 레이블이 중앙에 잘못 정렬 된 것 같습니다.

...
[self.navigationItem.titleView sizeToFit]; 
[label release]; // not needed if you are using ARC

iOS 7 용으로 업데이트되었습니다.

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
                                                      shadow, NSShadowAttributeName,
                                                      [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];

의례 :

http://www.appcoda.com/customize-navigation-status-bar-ios-7/


모든 답변에 그림자가 포함 된 이유가 확실하지 않습니다. 그림자를 조작하는 선을 추가하면 텍스트 글꼴 변경과 관련하여 아무 작업도 수행되지 않습니다. 이 두 줄의 코드는 iOS 8.4 및 Swift에서 작동합니다.

let attributesDictionary = [NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 14)!]
navigationController!.navigationBar.titleTextAttributes = attributesDictionary

titleTextAttributes저장 글꼴, 색상, 크기 및 탐색 모음의 제목의 다른 속성을 지시하는 사전.


iOS 5부터는 모양 프록시를 사용할 수 있습니다.

대답은이 질문의 중복입니다 : https://stackoverflow.com/a/12364740/883413


     NSShadow *shadow = [NSShadow new];
[shadow setShadowColor: [UIColor clearColor]];
[shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)];

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                         [UIFont fontWithName:@"TimeBurner" size:27.0f], NSFontAttributeName,
                                         [UIColor whiteColor], NSForegroundColorAttributeName,
                                         shadow, NSShadowAttributeName,nil]];

참고 URL : https://stackoverflow.com/questions/5832036/change-the-navigation-bars-font

반응형