导航条最近需要设置成透明的形式,最开始想通过颜色clearColor设置,设置透明度,结果发现UINavigationItem无法显示显示,后来通过setBackgroundImage设置成功,不过会多出一条线白线,需要通过setShadowImage设置背景图片,代码如下:
-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:[UIImage new]]; }
如果不想影响其他页面的导航透明度,viewWillDisappear将其设置为nil即可:
-(void)viewWillDisappear:(BOOL)animated{ //原文地址:http://www.cnblogs.com/xiaofeixiang [super viewWillDisappear:animated]; [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:nil]; }
时间: 2024-10-09 16:31:16