问题描述
我以编程方式向我的 UIViewController
添加了一个 UINavigationController
,如下所示:
I added a UINavigationController
to my UIViewController
programmatically like following:
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:[ViewController fromStoryboardNamed:@"myVC"]];
在调试视图层次结构中,我看到在带有灰色背景的 UINavigationBar
后面有一个名为 UIBackdropView
的视图.您可以在屏幕截图中看到:
and in the debug view hierarchy I see there is a view called UIBackdropView
behind the UINavigationBar
with gray color background. You can see that in the screenshot:
我试图在文档中找到它,但找不到.
I tried to find it in the Documentation,but I couldn't find any.
我们可以访问这一层吗?
Can we access this layer?
这会导致 UINavigationBar
下出现 1 像素的灰线.是否可以删除/隐藏 _UIBackDropView
?
This causes a 1 pixel gray line to appear under the UINavigationBar
. Is it possible to remove/hide the _UIBackDropView
?
我试图通过在覆盖这条暗线的 UINavigationBar
下添加一个简单的 UIView
和白色背景来混合这条 1 像素的线,并且效果很好.我想知道是否有办法隐藏/删除 BackdropView
而不是在它上面添加 UIView
.
I tried to blend this 1 pixel line by adding a simple UIView
with white background color under the UINavigationBar
which covers this dark line,and it worked fine. I would like to know If there is a way to hide/remove the BackdropView
instead of adding a UIView
on top of it.
推荐答案
官方来说,这只能通过将导航栏的 shadowImage
设置为空图像来实现,正如在另一个答案中提到的那样.不过仔细看文档,据说:
Officially, this is only possible by setting the shadowImage
of the navigationBar to an empty image, as has been mentioned in another answer. However, a closer look at the documentation, it is said:
要显示自定义阴影图像,还必须使用 setBackgroundImage:forBarMetrics: 方法设置自定义背景图像.如果使用默认背景图像,则无论此属性的值如何,都将使用默认阴影图像.
通过使用自定义背景图片,您会失去模糊的背景半透明效果,这可能不是您想要的.
By using a custom background image, you would lose the blurred background translucency, which is likely not what you want.
发际线"是一个 UIImageView,它是导航栏的一个子视图.您可以找到它并将其设置为隐藏.例如,这就是 Apple 在其原生日历应用程序中所做的.只需迭代子视图,并将图像视图设置为隐藏.
The "hairline" is a UIImageView that is a subview of the navigation bar. You can find it and set it as hidden. This is what Apple does in their native calendar app, for example. Just iterate the subviews, and set the image view to hidden.
这篇关于如何从导航栏中删除阴影线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!