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")