我以编程方式向我的 UIViewController
添加了一个 UINavigationController
,如下所示:
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:[ViewController fromStoryboardNamed:@"myVC"]];
在调试 View 层次结构中,我看到在 UINavigationBar
后面有一个名为 UIBackdropView
的 View ,背景为灰色。您可以在屏幕截图中看到:
我试图在文档中找到它,但找不到。
我们可以访问这一层吗?
这会导致 UINavigationBar
下方出现一条 1 像素的灰线。是否可以删除/隐藏 _UIBackDropView
?
我尝试通过在覆盖这条暗线的 UINavigationBar
下添加一个简单的带有白色背景色的 UIView
来混合这条 1 像素的线,并且它工作正常。我想知道是否有办法隐藏/删除 BackdropView
而不是在其上添加 UIView
。
最佳答案
正式来说,这只能通过将 navigationBar 的 shadowImage
设置为空图像来实现,正如另一个答案中提到的那样。但是,仔细查看文档,它说:
For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.
通过使用自定义背景图片,您会失去模糊的半透明背景,这可能不是您想要的。
“细线”是一个 UIImageView,它是导航栏的 subview 。您可以找到它并将其设置为隐藏。例如,这就是 Apple 在其原生日历应用程序中所做的。只需迭代 subview ,并将 ImageView 设置为隐藏即可。
关于ios - 如何从导航栏中删除阴影线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32208378/