iOS 设置导航栏大全

1.导航栏隐藏有效办法:
[self.navigationController setNavigationBarHidden:YES animated:YES];

2.设置图片为导航栏背景
// 竖屏下的图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bar.png"] forBarMetrics:UIBarMetricsDefault];

3.去除导航栏下方的横线
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

4.[self.navigationItem setHidesBackButton:YES]; // 隐藏返回按钮

5.修改按钮的渲染颜色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

6.设置左边按钮
UIImage *image = [UIImage imageNamed:@"tuichu_icon"];
// 取消渲染
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *bbi1 = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(tuichu)];
self.navigationItem.leftBarButtonItem = bbi1;

7.设置右边按钮
UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(gotoSearcherViewController)];
self.navigationItem.rightBarButtonItems = @[ bbi2];

8.修改导航栏title字体大小以及颜色
// 修改按钮的渲染颜色
// 修改按钮的渲染颜色
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:kFONT_HEITI_TC(17),NSForegroundColorAttributeName:[UIColor whiteColor]}];

9.设置导航栏背景色
self.navigationController.navigationBar.barTintColor = MainColor1;

10.设置self.title 颜色
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];

//修改索引颜色
tableView.sectionIndexBackgroundColor = [UIColor greenColor];//修改右边索引的背景色
tableView.sectionIndexColor = [UIColor orangeColor];//修改右边索引字体的颜色
tableView.sectionIndexTrackingBackgroundColor = [UIColor orangeColor];//修改右边索引点击时候的背景色

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容