iOS 修改NavigationBar

1、修改title的字体颜色以及字号大小

[self.navigationController.navigationBar setTitleTextAttributes:@{
                                                                      NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14.f],
                                                                      NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]
                                                                      }];

2、自定义返回按钮

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"bt_navigationBar_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
self.navigationItem.leftBarButtonItem = backBarButtonItem;

3、修改UIBarButtonItem的字体颜色和字号

UIBarButtonItem *lastPaper = [[UIBarButtonItem alloc] initWithTitle:@"上一张" style:UIBarButtonItemStylePlain target:self action:@selector(lastPaperAction)];
    [lastPaper setTitleTextAttributes:@{
                                        NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:12.f],
                                        NSForegroundColorAttributeName: [UIColor colorWithRed:13/255.0 green:194/255.0 blue:179/255.0 alpha:1]
                                        } forState:UIControlStateNormal];

UIBarButtonItem *nextPaper = [[UIBarButtonItem alloc] initWithTitle:@"下一张" style:UIBarButtonItemStylePlain target:self action:@selector(nextPaperAction)];
    [nextPaper setTitleTextAttributes:@{
                                        NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:12.f],
                                        NSForegroundColorAttributeName: [UIColor colorWithRed:13/255.0 green:194/255.0 blue:179/255.0 alpha:1]
                                        } forState:UIControlStateNormal];
    
    self.navigationItem.rightBarButtonItems = @[nextPaper, lastPaper];

你可能感兴趣的:(iOS 修改NavigationBar)