简体   繁体   中英

Can't set my navigation bar title's font size

I tried to figure out how to do this using StackOverflow and got this far:

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

Unfortunately, I get an error underlining UIFont.systemFontSize that says Bad receiver type 'CGFloat'(aka 'double') .

How do I tweak my code so that it becomes functional?

Your syntax is off for

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

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

You want to remove the period here UIFont.systemFontSize and instead use UIFont systemFontOfSize:weight:

Rather than trying to put everything inline when setting attributes, it can sometimes be helpful to separate them out ie:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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