隐藏NavigationBar下面的线(也许是阴影?)

首先 我们定义个属性

@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;

}

评论

此博客中的热门博文

使__attribute__((annotate("xxx")))能作用于OC函数

viewWillAppear不执行的解决办法

iOS中使用xpc/xpc.h