如何隐藏导航栏下的线

来源:互联网 发布:淘宝竞争情报 编辑:程序博客网 时间:2024/06/06 03:06

我们有时候需要隐藏掉导航栏下面的线那么我们怎么操作呢?

首先 我们定义个属性

@property (nonatomic,strong)UIImageView *contentLineImageView;

然后写一个方法:

- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {

    if ([viewisKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {

        return (UIImageView *)view;

    }

    for (UIView *subviewin view.subviews) {

        UIImageView *imageView = [selffindHairlineImageViewUnder:subview];

        if (imageView) {

            return imageView;

        }

    }

    returnnil;

}

//然后在viewdidload中调用这个方法

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

      _contentLineImageView = [selffindHairlineImageViewUnder:self.navigationController.navigationBar];

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:37/255.0green:195/255.0blue: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;

}

//具体代码如下图:

 效果如下图所示:


//没有颜色时候如下图所示:


这样 就把这条线给隐藏了。





1 0
原创粉丝点击