我跟着其他stackoverflow線程並創建CAShapeLayer並將其添加到按鈕層。如何只爲topLeft和bottomLeft角獲得圓角?
let bazierPath = UIBezierPath.init(roundedRect: button.bounds, byRoundingCorners: [UIRectCorner.bottomLeft, UIRectCorner.topLeft], cornerRadii: CGSize(width: 10.0, height: 10.0))
let shapeLayer = CAShapeLayer()
shapeLayer.frame = button.bounds
shapeLayer.path = bazierPath.cgPath
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.lineWidth = 1.0
button.layer.mask = shapeLayer
但問題是我越來越清晰的顏色的角落,但我希望他們是綠色的。檢查以下圖像中帶有「星期一」和「星期五」的按鈕,以清楚瞭解問題。
檢查:http://stackoverflow.com/questions/37163850/round-top-corners-of-a-uibutton-in-swift – Khuong