0
使用下面的代碼,我添加了一個彩色邊框並繞過了通過的角落。然而,當我調整UIView
編程,老邊區依然存在,我得到這個雙邊框:UITableViewCell中的UIView具有雙邊框
人有一個想法如何解決呢?我試過撥打cell.layoutSubviews()
和cell.layer.layoutSublayers()
。在設置邊框之前,我嘗試刪除邊框圖層並將圖層設置爲nil
。似乎沒有任何工作。
如果我不調整視圖的大小,那很好。
func roundCorners (view: UIView, corners: UIRectCorner, radius: CGFloat, color: String) {
let bounds = view.bounds
let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let maskLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = maskPath.cgPath
view.layer.mask = maskLayer
var borderColor = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 1.0)
switch color {
case "Green":
borderColor = UIColor(red: 130/255.0, green: 208/255.0, blue: 151/255.0, alpha: 0.9)
case "Red":
borderColor = UIColor(red: 243/255.0, green: 44/255.0, blue: 31/255.0, alpha: 1.0)
view.alpha = 0.5
case "Purp":
borderColor = UIColor(red: 102/255.0, green: 135/255.0, blue: 241/255.0, alpha: 0.7)
case "DarkBlue":
borderColor = UIColor(red: 90/255.0, green: 125/255.0, blue: 160/255.0, alpha: 0.6)
default:
borderColor = UIColor(red: 150/255.0, green: 150/255.0, blue: 150/255.0, alpha: 0.7)
}
let frameLayer = CAShapeLayer()
frameLayer.frame = bounds
frameLayer.path = maskPath.cgPath
frameLayer.strokeColor = borderColor.cgColor
frameLayer.lineWidth = 3
frameLayer.fillColor = nil
view.layer.addSublayer(frameLayer)
}
從cellForRowAt
調用:
roundCorners(view: cell.MoveCellTo_TodayList, corners: [.topLeft, .bottomLeft], radius: 8, color: "Green")