iOS - 实现导航栏透明的几种方法(总结)
2017-11-02 19:30
621 查看
前言:
在开发中,为了美观很多设计成导航栏透明的样式,下面就列举一下实现导航栏透明的几种方法
第一种方法:
作者:CoderBob
链接:http://www.jianshu.com/p/fddc4ee4bc1f
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
在开发中,为了美观很多设计成导航栏透明的样式,下面就列举一下实现导航栏透明的几种方法
第一种方法:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; for (UIView *aView in self.navigationController.navigationBar.subviews) { if ([aView isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) { aView.hidden = YES; } } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; for (UIView *aView in self.navigationController.navigationBar.subviews) { if ([aView isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) { aView.hidden = NO; } } }第二种方法:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; //去除 navigationBar 底部的细线 self.navigationController.navigationBar.shadowImage = [UIImage new];第三种方法
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init]; UIImage *image = [self createAImageWithColor:[UIColor clearColor] alpha:0.0]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
- (UIImage *)createAImageWithColor:(UIColor *)color alpha:(CGFloat)alpha{ CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextSetAlpha(context, alpha); CGContextFillRect(context, rect); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage; }注意点:设置导航栏透明的时候,如果在Push到其他的控制器,其他的控制器导航栏也是会变得透明,所以为了防止这类情况的发生,最好在
- (void)viewWillDisappear:(BOOL)animated方法中,把导航栏的颜色还原过来
作者:CoderBob
链接:http://www.jianshu.com/p/fddc4ee4bc1f
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
相关文章推荐
- iOS实现UIView渐变的几种方法以及实现渐变透明功能
- <iOS 导航栏>第一节:导航栏透明方法实现代码
- Android点击Button实现功能的几种方法总结
- iOS里常见的几种信息编码、加密方法简单总结
- Android 4.4 后透明状态栏和导航栏效果实现(学习总结)
- IOS自定义View实现相应的控件点击方法以及代理的总结(附代码)
- MFC中各种控件透明的实现方法总结
- iOS实现导航栏全透明效果
- ios设置导航栏透明方法:使用只有一个像素点的透明图片,通过以下代码即可
- Android点击Button实现功能的几种方法总结
- IOS-56-UIWebview浏览器中自定义底部导航栏透明效果的实现
- 【续】用ObjectDataSource实现自定义分页的心得总结,几种分页方法的性能对比
- iOS单例模式的实现方法总结
- 谈谈你对多线程开发的理解?ios中有几种实现多线程的方法?
- iOS几种传值方法的总结
- IOS动画的使用方法总结-下拉框的简单实现
- 几种常见的载入中、loading页面效果的实现方法总结
- iOS 导航栏实现总结
- iOS: performXXX的几种方法总结:
- 用django实现redirect的几种方法总结