您的位置:首页 > 其它

导航栏设置为透明

2015-11-27 15:05 162 查看
给导航栏加一个透明的背景:

[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)}];
}//意味着只有这个界面是白色字体的导航栏,将要消失时设置为别的界面需要的统一的导航栏的字体


最后付上效果图片:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: