如何在iOS 7中删除UINavigationBar内部阴影? [英] How to remove UINavigationBar inner shadow in iOS 7?

查看:94
本文介绍了如何在iOS 7中删除UINavigationBar内部阴影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内部阴影示例



<我试图将导航栏放在另一个导航栏下方,使其看起来像一个高大的导航栏。但是在iOS 7中,UINavigationBar现在在其顶部和底部都有内部阴影。我真的需要删除它。但我没有找到任何解决方案。它看起来像预渲染阴影,但实际上它在视图出现后大约0.4秒内缓慢出现。



我几乎尝试了所有东西,但影子仍在那里。我用以下代码删除了条形下方的水平线:

  for([[[self.navigationController.navigationBar]中的UIView *视图subviews] objectAtIndex:0] subviews]){
if([view isKindOfClass:[UIImageView class]])view.hidden = YES;
}

但我无法弄清楚如何移除阴影。非常感谢!



我试过这个:

  [ self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]]; 

但该代码甚至不会删除栏下方的水平线(此方法需要自定义背景图片)。我使用Xcode版本5.0(5A11365x)

解决方案

导航栏底部的水平线就是shadowImage。
可以通过应用空的 UIImage 来删除它。
根据文档,您还必须设置自定义背景图像:

   - (void)viewDidLoad 
{
[super viewDidLoad];

//设置背景和阴影图像以摆脱线条。
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}


Inner shadow example

I'm trying to put nav bar below the other one to make it look like one tall nav bar. But in iOS 7 UINavigationBar now has inner shadow on top and on bottom of it. I really need to remove it. But I didn't found any solution. It looks like the shadow is prerendered, but in fact it slowly appears in about 0.4 second after the view appears.

I've tried almost everything but the shadow is still there. I removed the horizontal line below the bar with this code:

for (UIView *view in [[[self.navigationController.navigationBar subviews] objectAtIndex:0] subviews]) {
     if ([view isKindOfClass:[UIImageView class]]) view.hidden = YES;
}

But I can't figure it out how to remove the shadow. Thanks a lot!

I've tried this:

[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];

But that code doesn't even remove the horizontal line below the bar (this method needs custom background image). I use Xcode Version 5.0 (5A11365x)

解决方案

The "horizontal" line at the bottom of the navigation bar is simply it's shadowImage. It can simply be removed by applying an empty UIImage. According to the documentation you also have to set a custom background image:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Set the background and shadow image to get rid of the line.
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}

这篇关于如何在iOS 7中删除UINavigationBar内部阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆