2013-10-24 4 views
7

기본적으로 UIBarButtonItem은 스타일 UIBarButtonItemStylePlain에 Helvetica 일반 가중치 글꼴을 사용하고 UIBarButtonItemStyleDone에 대담한 가중치를 사용합니다.iOS7에서 UIBarButtonItems는 UIAppearance 프록시를 사용할 때 대담한 "완료"스타일을 준수하지 않습니다.

내 응용 프로그램은 사용자 정의 글꼴을 사용하고, 나는 이것을 달성하기 위해 UIAppearance 프록시를 사용하고 있습니다 :

appearance = @{NSFontAttributeName: [UIFont fontWithName:@"ProximaNova-Regular" size:18.0]}; 
[[UIBarButtonItem appearance] setTitleTextAttributes:appearance 
              forState:UIControlStateNormal]; 

문제는, 모양 프록시하게되어 일반 및 완료 스타일 단추 나는 위에서 지정한 일정한 무게 글꼴 .

아이디어에 따라 스타일에 따라 다른 사용자 정의 글꼴 가중치를 사용하도록 UIBarButtonItem을 얻을 수있는 방법은 무엇입니까?

+0

이봐 마크 :-) 내 오타의 탐지를위한 감사합니다, 나는이 긴 연체 알고 대답을했지만 UIBarButtonItem의 하위 클래스를 만들고 사용자 정의보기를 추가하려고 했습니까? 이 대답을 여기에서보십시오 : http://stackoverflow.com/questions/18844681/how-to-make-custom-uibarbuttonitem-with-image-and-label. 희망이 도움이 :) –

답변

3

내가 그것을 늦게 답을 알고 있지만, 누군가를 위해 도움이 될 수 있습니다

UIBarButtonItem *customBarButton = 
     [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"CustomTitle", @"This button appears in my smexy ViewController's naviagtion bar") 
             style:UIBarButtonItemStylePlain 
             target:self 
             action:@selector(customButtonDidClick:)]; 

    NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:14.0f], 
           NSForegroundColorAttributeName: [UIColor redColor]}; // here you can add some other keys (especially in iOS 7) to personalize your button title more 

    [customBarButton setTitleTextAttributes:attributes forState:UIControlStateNormal]; 

    [self.navigationItem setRightBarButtonItem:customBarButton]; 

편집 :

+0

Thanks @Neru! 그거야. 참고 : 글꼴 문자열 앞에 @가 없습니다. –

+0

기꺼이 도와 드리겠습니다 :-) – Neru

+1

이 코드가 문제를 해결하는 방법을 이해할 수 없습니다 ... – Fry