原文:(http://blog.csdn.net/hherima/article/details/44218915)
方法一.当设置navigationBar的背景图片时移除黑线的方法,该方法会使translucent属性失效
[objc] view plain copy
//方法一.当设置navigationBar的背景图片时移除黑线的方法,该方法会使translucent属性失效
-(void)useShadowImageRemoveBlackLine
{
//通过设置shadowImage移除黑线
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
方法二.当设置navigationBar的背景图片或背景色时,使用该方法都可移除黑线,且不会使translucent属性失效(推荐)[objc] view plain copy
//方法二.当设置navigationBar的背景图片或背景色时,使用该方法都可移除黑线,且不会使translucent属性失效
-(void)useMethodToFindBlackLineAndHind
{
UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
//隐藏黑线(在viewWillAppear时隐藏,在viewWillDisappear时显示)
blackLineImageView.hidden = YES;
}
- (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;
}
方法三.简单移除黑线方法
[objc] view plain copy
//方法三.简单移除黑线方法
-(void)useClipsToBoundsRemoveBlackLine
{
//设置移除黑线
self.navigationController.navigationBar.clipsToBounds = YES;
}
方法四.移除黑线(不推荐)[objc] view plain copy
//方法四.移除黑线(不推荐)
-(void)removeBlackLine
{
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
网友评论