导航栏设置为透明

来源:互联网 发布:java多个线程并发实现 编辑:程序博客网 时间:2024/05/22 05:01

给导航栏加一个透明的背景:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tm"] forBarMetrics:UIBarMetricsCompact];

并加代码:

self.navigationController.navigationBar.layer.masksToBounds = YES;//去掉黑线

如果tableView在导航栏的下方的话可以设置代码:

 self.edgesForExtendedLayout = YES;    self.automaticallyAdjustsScrollViewInsets = NO;

同时要想改变导航栏上字体的颜色:

[self.navigationController.navigationBar setTitleTextAttributes:     @{NSFontAttributeName:[UIFont systemFontOfSize:20],       NSForegroundColorAttributeName:[UIColor whiteColor]}];

若添加了这个代码后影响了别的界面的导航栏的颜色,可以在本界面再加入代码:

- (void) viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    [self.navigationController.navigationBar setTitleTextAttributes:     @{NSFontAttributeName:[UIFont systemFontOfSize:20],       NSForegroundColorAttributeName:CLColor(68.0f, 68.0f, 68.0f)}];}//意味着只有这个界面是白色字体的导航栏,将要消失时设置为别的界面需要的统一的导航栏的字体

最后付上效果图片:
这里写图片描述

0 0
原创粉丝点击