0
点赞
收藏
分享

微信扫一扫

iOS 导航栏设置

左手梦圆 2022-02-18 阅读 78
  • 导航栏右侧的Done按钮怎么是蓝色的?
  • 导航栏右侧按钮大小设置
  • 导航栏标题按钮样式设置
  • 导航栏设置颜色

iOS 13之后使用UINavigationBarAppearance来设置标题,按钮的颜色和大小,导航栏的背景等。

#import "MMBaseNavigationController.h"

@interface MMBaseNavigationController ()

@end

@implementation MMBaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    /// Config the navigation bar apperance
    
    if (@available(iOS 13.0, *)) {
        // Config the done button appearance
        UIBarButtonItemAppearance *doneAppearance = [[UIBarButtonItemAppearance alloc] init];
        doneAppearance.normal.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]};
        // Config the back button appearance
        UIBarButtonItemAppearance *backButtonAppearance = [[UIBarButtonItemAppearance alloc] init];
        backButtonAppearance.normal.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]};
        
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        // Navigation bar background image
        appearance.backgroundImage = [WMSTools loadImage:@"top"];
        // Navigation bar title
        appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]};
        // Set the Done button appearance
        appearance.doneButtonAppearance = doneAppearance;
        // Set the navigation bar appearance.
        self.navigationBar.standardAppearance = appearance;
    }
    else {
        [[UINavigationBar appearance] setBackgroundImage:[WMSTools loadImage:@"top"] forBarMetrics:UIBarMetricsDefault];
        [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    }
}

@end
举报

相关推荐

0 条评论