美文网首页iOS 技术文档收录
自定义iOS7导航栏背景,标题和返回按钮文字颜色

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

作者: LuxDark | 来源:发表于2015-12-22 09:49 被阅读409次

1.更改导航栏的背景和文字的颜色。
方法一:
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];

方法二:
//设置NavigationBar背景颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
//@{}代表Dictionary
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

2.导航栏背景使用图片
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
3.添加多个导航栏按钮
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action: nil nil];
UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action: nil nil];
NSArray *itemsArr = @[shareItem,cameraItem];
self.navigationItem.rightBarButtonItems = itemsArr;

4.解决系统返回按钮和导航栏背景颜色相同问题
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

相关文章

网友评论

    本文标题: 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    本文链接:https://www.haomeiwen.com/subject/pwnmhttx.html