我正在尝试使用定义颜色向UIToolBar添加顶部唯一边框。目前,我使用以下代码来提供透明外观.ToolBar看起来没问题。但是,我在工具栏中获得了黑色顶部边框线我想把那个黑色边框改成白色。
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
提前致谢....
答案 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)
答案 1 :(得分:0)
我只想弄清楚答案。简单地说,我在工具栏上方放置了一条发线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)
我使用以下代码从toolBar
中删除黑色现有边界线 self.navigationController?.toolbar.clipsToBounds = true
以上代码有效并且看起来很棒。任何,改进的答案将不胜感激....