在Swift中将仅顶部边框添加到UIToolBar
我正在尝试使用“定义颜色”将顶部边框添加到UIToolBar。当前,我使用以下代码提供透明外观。工具栏看起来正常。但是,我在工具栏中得到一条黑色顶部边框线。我想将黑色边框更改为白色在Swift中将仅顶部边框添加到UIToolBar,swift,uitoolbar,Swift,Uitoolbar,我正在尝试使用“定义颜色”将顶部边框添加到UIToolBar。当前,我使用以下代码提供透明外观。工具栏看起来正常。但是,我在工具栏中得到一条黑色顶部边框线。我想将黑色边框更改为白色 My Code: navigationController?.toolbar.setBackgroundImage(UIImage(), forToolbarPosition: UIBarPosition.any, barMetrics: UIBarMetrics.default) navig
My Code:
navigationController?.toolbar.setBackgroundImage(UIImage(), forToolbarPosition: UIBarPosition.any, barMetrics: UIBarMetrics.default)
navigationController?.toolbar.barStyle = UIBarStyle.default
navigationController?.toolbar.tintColor = UIColor.white
navigationController?.toolbar.backgroundColor = UIColor(white: 0.6, alpha: 0.2)
// To remove the black border line. If, I want to
self.navigationController?.toolbar.clipsToBounds = true
// I don't want to put a border around the UIToolbar like below code
self.navigationController?.toolbar.layer.borderColor = UIColor.white.cgColor
self.navigationController?.toolbar.layer.borderWidth = 0.2
提前感谢….试试这个:
let path = UIBezierPath()
path.move(to: CGPoint(x: mytabbr.bounds.minX, y: mytabbr.bounds.minY ))
path.addLine(to: CGPoint(x: mytabbr.bounds.maxX, y: mytabbr.bounds.minY ))
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.strokeColor = UIColor.black.cgColor
shape.fillColor = UIColor.clear.cgColor
shape.lineWidth = 2
shape.lineCap = kCALineCapRound
mytabbr.layer.addSublayer(shape)
试试这个:
let path = UIBezierPath()
path.move(to: CGPoint(x: mytabbr.bounds.minX, y: mytabbr.bounds.minY ))
path.addLine(to: CGPoint(x: mytabbr.bounds.maxX, y: mytabbr.bounds.minY ))
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.strokeColor = UIColor.black.cgColor
shape.fillColor = UIColor.clear.cgColor
shape.lineWidth = 2
shape.lineCap = kCALineCapRound
mytabbr.layer.addSublayer(shape)
我只是找到了答案。简单地说,我在工具栏上方放置了一个发际线视图
let lineView = UIView(frame: CGRect(x:0, y:0, width:view.frame.width, height:0.2))
lineView.backgroundColor=UIColor.white.withAlphaComponent(0.6)
self.navigationController?.toolbar.addSubview(lineView)
我使用下面的代码从工具栏中删除了黑色的现有边界线
self.navigationController?.toolbar.clipsToBounds = true
上面的代码很好用,看起来也很不错。任何改进的答案都将受到欢迎。…我只是想知道答案。简单地说,我在工具栏上方放置了一个发际线UIView
let lineView = UIView(frame: CGRect(x:0, y:0, width:view.frame.width, height:0.2))
lineView.backgroundColor=UIColor.white.withAlphaComponent(0.6)
self.navigationController?.toolbar.addSubview(lineView)
我使用下面的代码从工具栏中删除了黑色的现有边界线
self.navigationController?.toolbar.clipsToBounds = true
以上代码工作正常,看起来很棒。如有任何改进,将不胜感激