【发布时间】:2018-07-05 23:57:46
【问题描述】:
我正在为这样的视图添加边框:
extension UIView {
func addTopBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x:0,y: 0, width:self.frame.size.width, height:width)
self.layer.addSublayer(border)
}
}
在 viewDidLoad 中:
textLbl.addTopBorderWithColor(color: UIColor.white, width: 1)
在视图中将出现:
textLbl.text = "placeholder text \(variableLengthText)"
如何消除使用上述扩展程序绘制的边框?
【问题讨论】:
标签: swift uiview calayer cgrect