ios - 如何从导航栏中删除阴影线?

标签 ios uinavigationcontroller uinavigationbar

我以编程方式向我的 UIViewController 添加了一个 UINavigationController,如下所示:

 UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:[ViewController fromStoryboardNamed:@"myVC"]];

在调试 View 层次结构中,我看到在 UINavigationBar 后面有一个名为 UIBackdropView 的 View ,背景为灰色。您可以在屏幕截图中看到:

enter image description here

我试图在文档中找到它,但找不到。

我们可以访问这一层吗?

这会导致 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/

相关文章:

ios - 无法在多行 nsstring 上获得投影

ios - 交互式转换 : navigation bar appearance issue

iphone - 为什么只有 viewWillAppear 在返回导航时被调用

swift - searchBar过滤的tableViewCells didSelectItemAt indexPath显示在navigationBar标题中

ios - UIView 应该观察通知吗?

iphone - 点击按钮时忽略 UIGestureRecognizer

ios - UINavigationController子类方便初始化使子类常量init两次

ios - 从自定义相机中删除取消按钮

ios - 返回首页 UIViewController

android - 将现有桌面应用程序重新架构为支持多平台的技术