iOS开发中如何隐藏导航栏下的线条
2015-11-03 19:15
567 查看
我们有时候需要隐藏掉导航栏下面的线那么我们怎么操作呢?
首先 我们定义个属性
@property (nonatomic, strong)UIImageView *contentLineImageView;
然后写一个方法:
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
if ([view isKindOfClass:UIImageView.class]
&& view.bounds.size.height <= 1.0) {
return (UIImageView *)view;
}
for (UIView *subview in view.subviews)
{
UIImageView *imageView = [self findHairlineImageViewUnder:subview];
if (imageView) {
return imageView;
}
}
return nil;
}
//然后在viewdidload中调用这个方法
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_contentLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
self.navigationController.navigationBar.barTintColor =
[UIColor colorWithRed:37/255.0 green:195/255.0 blue:149/255.0alpha:1.0f];
//这句话 要写上。 默认是YES可能你得到的颜色与实际的不匹配。 默认为YES 说明是有透明度的。
self.navigationController.navigationBar.translucent = NO;
}
//做了这些操作还不够 我们还需要在viewwillappear 和viewwilldisappear 里写下下面的方法。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_contentLineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_contentLineImageView.hidden = NO;
}
//具体代码如下图:
![](http://img.blog.csdn.net/20150820204218290?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
效果如下图所示:
![](http://img.blog.csdn.net/20150820204228513?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
//没有颜色时候如下图所示:
![](http://img.blog.csdn.net/20150820204526051?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
这样 就把这条线给隐藏了。
博主Swfit学习笔记博客地址点击打开链接
首先 我们定义个属性
@property (nonatomic, strong)UIImageView *contentLineImageView;
然后写一个方法:
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
if ([view isKindOfClass:UIImageView.class]
&& view.bounds.size.height <= 1.0) {
return (UIImageView *)view;
}
for (UIView *subview in view.subviews)
{
UIImageView *imageView = [self findHairlineImageViewUnder:subview];
if (imageView) {
return imageView;
}
}
return nil;
}
//然后在viewdidload中调用这个方法
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_contentLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
self.navigationController.navigationBar.barTintColor =
[UIColor colorWithRed:37/255.0 green:195/255.0 blue:149/255.0alpha:1.0f];
//这句话 要写上。 默认是YES可能你得到的颜色与实际的不匹配。 默认为YES 说明是有透明度的。
self.navigationController.navigationBar.translucent = NO;
}
//做了这些操作还不够 我们还需要在viewwillappear 和viewwilldisappear 里写下下面的方法。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_contentLineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_contentLineImageView.hidden = NO;
}
//具体代码如下图:
效果如下图所示:
//没有颜色时候如下图所示:
这样 就把这条线给隐藏了。
博主Swfit学习笔记博客地址点击打开链接
相关文章推荐
- iOS提交被拒
- 一个iOS应用开发背后的流程
- IOS开发技巧--模拟器 cannot run 项目.
- FFmpeg在iOS上完美编译
- iOS推送证书的生成
- 绘图与动画之使用自定义属性与Quartz实现扇形加载动画
- IOS代码添加控件,控件移动,放大,缩小,旋转
- nagios详细讲解
- iOS沙盒机制和文件读写
- iOS沙盒机制和文件读写
- iOS Xcode, 解决“Could not insert new outlet connection”的问题。(我使用第二种方法成功了)
- 白盒1:iOS静态代码扫描
- 制作iOS Ad-Hoc测试应用
- 使用蒲公英来做iOS测试应用的分发
- ios message sent to deallocated instance 重复release 内存问题
- iOS开发中自定义按钮
- iOS开发之使用CocoaPods更新第三方出现“target overrides the `OTHER_LDFLAGS`……”问题解决方案
- iOS开发——字符串去除回车符和两端空格
- iOS小记
- IOS 开发过程中常用的系统 函数