iOS - Globally change navigation bar title color using appearance?

前端 未结 6 1713
情歌与酒
情歌与酒 2021-02-07 00:56

This crashes the app:

[[UINavigationBar appearance] setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];

Is there a way to do

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 01:42

    I used following code to change the title bar's color.

    NSShadow *shadow = [[NSShadow alloc] init];
    shadow.shadowColor = [UIColor blackColor];
    shadow.shadowOffset = CGSizeMake(1, 0);
    
    NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
                                                NSShadowAttributeName:shadow};
    
    [[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];
    

提交回复
热议问题