我有一个应用程序,有时需要它的导航栏融入内容。
有人知道怎么去掉或者改变这个烦人的小条的颜色吗?
在下图中,我说的是根视图控制器下面1px的高度线
我有一个应用程序,有时需要它的导航栏融入内容。
有人知道怎么去掉或者改变这个烦人的小条的颜色吗?
在下图中,我说的是根视图控制器下面1px的高度线
当前回答
设置背景图像的问题是它消除了模糊。您可以在不设置背景图像的情况下删除它。在这里看到我的答案。
其他回答
适用于iOS 13+
窍门是用透明背景初始化'UINavigationBarAppearance'。然后,您可以轻松地删除导航栏的水平线。
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.backgroundColor = .green // Required background color
最后,按照apple的建议将外观更改添加到导航项中。
self.navigationItem.standardAppearance = appearance
self.navigationItem.scrollEdgeAppearance = appearance
self.navigationItem.compactAppearance = appearance
这里有一个非常重要的注意事项——改变UIViewController的navigationItem的外观比直接改变navigationBar要灵活得多。
为什么这么问?
For the simple reason that the navigationItem is tied to a single UIViewController and represents the state of the navigationBar for that particular UIViewController. This is big, as you don't have to handle the navigation bar changes between different view controllers within viewWillAppear (or something similar), as you would if you mutated the navigationBar; which is, remember, shared between all view controllers of a given navigation stack (UINavigationController), and changing it in one place changes it for all view controllers up to the stack.
你只要为一个特定的视图控制器设置正确的UINavigationBarAppearance, UIKit就会正确地更新导航栏样式,这取决于当前哪个视图控制器是导航堆栈上的顶视图控制器。
navigationItem.standardAppearance` = `UINavigationBarAppearance()
设置背景图像的问题是它消除了模糊。您可以在不设置背景图像的情况下删除它。在这里看到我的答案。
我的方法:
UINavigationBar.appearance().setBackgroundImage(
UIImage(),
forBarPosition: .Any,
barMetrics: .Default)
var _width:CGFloat! = self.navigationController?.navigationBar.layer.frame.width
var _height:CGFloat! = self.navigationController?.navigationBar.layer.frame.height
var navBarBg = UIView(frame:CGRectMake(0, 0, _width, _height))
//solid color for bg
navBarBg.backgroundColor = UIColor.orangeColor()
view.addSubview(navBarBg)
斯威夫特4 //隐藏导航栏阴影线
navigationController?.navigationBar.shadowImage = UIImage()