有没有办法设置仅在Tabbar顶部具有曲线边缘的线?
喜欢这张图片
我尝试了以下代码:
//Add top white line above tabbar
let lineView = UIView(frame: CGRect(x: 0, y: 0, width:self.tabBar.frame.size.width, height: 3))
lineView.backgroundColor = UIColor.white
lineView.layer.masksToBounds = true
lineView.clipsToBounds = true
lineView.layer.cornerRadius = 20.0
self.tabBar.layer.borderColor = UIColor.green.cgColor
self.tabBar.layer.borderWidth = 3
self.tabBar.addSubview(lineView)
但是它将图层添加到整个Tabbar。
我也尝试过此代码:
// Add rounded corners
let maskLayer = CAShapeLayer()
maskLayer.frame = self.tabBar.bounds
maskLayer.path = UIBezierPath(roundedRect: self.tabBar.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
self.tabBar.layer.mask = maskLayer
// Add border
let borderLayer = CAShapeLayer()
borderLayer.path = maskLayer.path
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.strokeColor = UIColor.green.cgColor
borderLayer.lineWidth = 3
borderLayer.frame = self.tabBar.bounds
self.tabBar.layer.addSublayer(borderLayer)
但是问题是相同的,它正在添加到整个视图中