无法设置导航栏标题的字体大小

时间:2019-01-09 22:56:54

标签: ios objective-c

我试图弄清楚如何使用StackOverflow来做到这一点,并走了很远:

[self.navController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont.systemFontSize:17 weight: UIFontWeightSemibold]}];

不幸的是,我在显示UIFont.systemFontSize的{​​{1}}下划线时遇到错误。

我如何调整代码以使其起作用?

1 个答案:

答案 0 :(得分:1)

您的语法已关闭

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight NS_AVAILABLE_IOS(8_2);

https://developer.apple.com/documentation/uikit/uifont/1619027-systemfontofsize?language=objc

您想在UIFont.systemFontSize处删除句点,而改用UIFont systemFontOfSize:weight:

设置属性时,与其尝试将所有内容都内联,不如将其分离出来有时是有帮助的:

    UIColor *whiteColor = [UIColor whiteColor];
    UIFont *navBarTitleFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightSemibold];
    [self.navigationController.navigationBar setTitleTextAttributes:@{
                                                                      NSForegroundColorAttributeName: whiteColor,
                                                                      NSFontAttributeName: navBarTitleFont
                                                                      }];