我怎样才能删除UIToolBar顶部边框

我已经将我的UIToolBar tint颜色设置为某个值,并且有我想要删除的此边框线:

在这里输入图像说明

我如何删除这个黑色边框>

正确的答案是极权主义的… FYI。 我的回应仍在下面供参考。


这是我做了我的白色背景工具栏…

whiteToolBar.layer.borderWidth = 1; whiteToolBar.layer.borderColor = [[UIColor whiteColor] CGColor]; 

也许你可以用你的颜色做同样的事情。

你可以这样做:

 self.navigationController.toolbar.clipsToBounds = YES; 
 toolbar1.clipsToBounds = YES; 

为我工作,因为有人还在用导航栏尝试

setShadowImage设置为[UIImage new]

设置样式为UIBarStyleBlackTranslucent为我做了(iOS 6)

这不适用于iOS版本,似乎不适用于iOS7。 我在另一个问题上回答了这个问题: https : //stackoverflow.com/a/19893602/452082 ,你可以修改该解决scheme,只是删除背景阴影(和离开你的toolbar.backgroundColor你喜欢的颜色)

我对这些答案有些困惑,但是我错过了使用Outlet的观点,所以在这里要清楚的是我用来隐藏边界的Swift代码:

 import UIKit class ViewController: UIViewController { //MARK Outlets @IBOutlet weak var ToolBar: UIToolbar! //MARK View Functions override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // Hide the bottom toolbar's top border ToolBar.clipsToBounds = true } } 

我已经拖动了一个工具栏到这个视图的底部,这不是顶部的导航栏一些其他问题引用。

clipsToBounds技术剪辑UIToolBar的阴影以及背景视图。 在iPhone X上,这意味着背景不再到达安全区域之外。

在iPhone X上不正确的UIToolBar

下面的解决scheme使用掩码来仅剪辑UITabBar的顶部。 蒙版呈现在UIToolBar子类中,蒙版框架在layoutSubviews的覆盖中保持更新。

 class Toolbar: UIToolbar { fileprivate let maskLayer: CALayer = { let layer = CALayer() layer.backgroundColor = UIColor.black.cgColor return layer }() override init(frame: CGRect) { super.init(frame: frame) initialize() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) initialize() } fileprivate func initialize() { layer.mask = maskLayer // Customize toolbar here } override func layoutSubviews() { super.layoutSubviews() // height is an arbitrary number larger than the distance from the top of the UIToolbar to the bottom of the screen maskLayer.frame = CGRect(x: -10, y: 0, width: frame.width + 20, height: 500) } } 

在iPhone X上更正UIToolBar