繁体   English   中英

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

[英]Can't set my navigation bar title's font size

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

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

不幸的是,我在UIFont.systemFontSize下划线出现错误,提示Bad receiver type 'CGFloat'(aka 'double')

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

您的语法已针对

+ (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.systemFontSize ,而改为使用UIFont systemFontOfSize:weight:

设置属性时,与其尝试使所有内容都内联,不如将它们分开可能会有所帮助,即:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM