27

UINavigationControllerBar の [戻る] ボタンのテキストのフォントの色を変更しようとしています

    [[UIBarButtonItem appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

このエラーが表示されます: [_UIBarItemAppearance setTitleColor:forState:]: 認識されないセレクターがインスタンス 0x69aeb70 に送信されました'

何か助けはありますか?ありがとう!

4

5 に答える 5

50
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithRed:(163.0f/255.0f) green:(0.0f) blue:(0.0f) alpha:1.0f] forKey:UITextAttributeTextColor];
[attributes setValue:[UIColor clearColor] forKey:UITextAttributeTextShadowColor];
[attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];

うまくいくようです!

于 2012-04-06T20:47:42.193 に答える
15

代わりにこれを使用してください。ios 5 で利用可能なデフォルト機能

UIBarButtonItem *backbutton =  [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nil action:nil];    

    [backbutton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor blackColor],UITextAttributeTextColor,[UIFont fontWithName:TEXTFONT size:16.0f],UITextAttributeFont,
                                                   nil] forState:UIControlStateNormal]; 
于 2012-05-04T14:19:47.767 に答える
3

Swift 4 での解決策:

UIBarButtonItem.appearance().setTitleTextAttributes(
[
    NSAttributedStringKey.font: UIFont(name: "MyriadPro-SemiboldCond", size: 16)!,
    NSAttributedStringKey.foregroundColor: UIColor.white
], for: .normal)

これを AppDelegate に追加すると、アプリ内のすべてのボタンに適用されます。

于 2018-03-01T09:33:48.333 に答える