给导航栏加一个透明的背景:
[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)}];
}//意味着只有这个界面是白色字体的导航栏,将要消失时设置为别的界面需要的统一的导航栏的字体
最后付上效果图片: