Fonts 更改uinavigationcontroller上“后退”按钮的字体

Fonts 更改uinavigationcontroller上“后退”按钮的字体,fonts,uinavigationcontroller,back-button,Fonts,Uinavigationcontroller,Back Button,我正在尝试更改UINavigationControllerBar中“后退”按钮上文本的字体颜色 [[UIBarButtonItem appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 给出以下错误:[[u UIBarItemAppearance setTitleColor:forState:]:无法识别的选择器发送到实例0x69aeb70' 有什么帮助吗?谢谢 NSMutableDic

我正在尝试更改UINavigationControllerBar中“后退”按钮上文本的字体颜色

    [[UIBarButtonItem appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
给出以下错误:[[u UIBarItemAppearance setTitleColor:forState:]:无法识别的选择器发送到实例0x69aeb70'

有什么帮助吗?谢谢

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];

似乎有用

使用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]; 

还有漂亮的解决方案iOS7+(因为属性名):

Swift 4中的解决方案:

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

在AppDelegate中添加此选项,它将应用于应用程序中的所有按钮。

使用外观选项是更好的解决方案。它们全局工作,或按类工作,或按实例工作。任何来这里的人都应该使用这个答案,这完全取决于情况。我正在制作一个游戏,只需要暂时更改字体[[UIBarButtonItem外观]setTitleTextAttributes:[NSDictionary Dictionary WithObjectsAndKeys:[UIColor colorWithRed:255.0/255.0绿色:255.0/255.0蓝色:255.0/255.0 alpha:1.0],NSForegroundColorAttributeName,[UIFontWithName:@“常规铜”大小:14.0],NSFontAttributeName,nil]用于状态:UIControlStateNormal];更完美的是将fontFor IOS7更改为FontAttributeFont,将UITextAttributeFont替换为NSFontAttributeName在iOS8上运行完美,而且我将UITextAttributeFont更改为NSFontAttributeName,它在IOS7+上也运行正常。Itgiawa的答案是有效的。似乎有一个错误,只在查看按钮的几秒钟内应用字体。Seems将仍然存在于iOS 12中。
NSShadow *shadow = [NSShadow new];
[shadow setShadowColor: [UIColor colorWithWhite:0.0f alpha:0.750f]];
[shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)];

[[UIBarButtonItem appearance] setTitleTextAttributes:@{
        NSFontAttributeName: [UIFont systemFontOfSize:24],
        NSForegroundColorAttributeName: [UIColor colorWithWhite:0.2 alpha:1.0],
        NSShadowAttributeName: shadow,
} forState:UIControlStateNormal];
UIBarButtonItem.appearance().setTitleTextAttributes(
[
    NSAttributedStringKey.font: UIFont(name: "MyriadPro-SemiboldCond", size: 16)!,
    NSAttributedStringKey.foregroundColor: UIColor.white
], for: .normal)