自定义导航栏的背景色 标题颜色字体 返回按钮的颜色和文字

//设置导航条的背景颜色
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
//没有啥用navigationBar.backgroundColo,因为他被_UINavigationBarBackground挡住了

自定义导航栏的背景色 标题颜色字体 返回按钮的颜色和文字_第1张图片
Paste_Image.png
//    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
//设置导航条的返回item的颜色
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

//自定义返回按钮的两种方法 1在上一级vc 2在本级vc

//方法1:这个方法需要在上一级的vc中设置 push到本界面生效
//    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"哈哈" style:UIBarButtonItemStylePlain target:nil action:nil];
//    self.navigationItem.backBarButtonItem = item;
//    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
//    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

//方法2 利用图片和移动文字的位置
UIImage *backButtonImage = [[UIImage imageNamed:@"返回按钮白"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];

图片拉伸的作用 防止图片显示有误
http://www.jianshu.com/p/a577023677c1

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//将返回按钮的文字position设置不在屏幕上显示
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

还有一种不规范的方法,用leftBarButtonItem来显示backBarButtonItem的效果
// CGRect backFrame = CGRectMake(0, 0, 20*yscale, 18*yscale);
//    UIButton *leftButton = [[UIButton alloc]initWithFrame:backFrame];
//    
//    UIImage *leftImage = [UIImage imageNamed:@"返回按钮白"];
//    [leftButton setBackgroundImage:leftImage forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(goBackClick) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
//    
//    self.navigationItem.leftBarButtonItem = leftBarButtonItem;

//设置title的文字大小 颜色
NSDictionary *navAttrDict = @{
                              NSFontAttributeName:[UIFont boldSystemFontOfSize:18],
                              NSForegroundColorAttributeName : [UIColor whiteColor]
                              };
[self.navigationController.navigationBar setTitleTextAttributes:navAttrDict];
//不透明背景
self.navigationController.navigationBar.translucent = NO;
自定义导航栏的背景色 标题颜色字体 返回按钮的颜色和文字_第2张图片
Paste_Image.png

参考文章:
http://blog.csdn.net/mad1989/article/details/41516743(强推)
http://blog.csdn.net/u011096206/article/details/50606778
http://hovertree.com/h/bjaf/45l087jt.htm
http://www.cocoachina.com/ios/20150409/11505.html
http://blog.csdn.net/zhuzhihai1988/article/details/7705308
http://blog.csdn.net/l863784757/article/details/45099791
http://blog.csdn.net/defuliu66/article/details/51330019
http://www.cocoachina.com/bbs/read.php?tid-153502-page-1.html
http://blog.csdn.net/sky837/article/details/39025173
http://www.cocoachina.com/bbs/read.php?tid=1687347
http://www.jianshu.com/p/6f3bc1da18f3(不错)

你可能感兴趣的:(自定义导航栏的背景色 标题颜色字体 返回按钮的颜色和文字)