【发布时间】:2021-09-23 13:18:32
【问题描述】:
在这里您可以看到 TableViewell 内部的视图:
添加虚线边框的代码如下:
func addDashedBorder()
{
let color = UIColor(displayP3Red: 178.0/255.0, green: 181.0/255.0, blue: 200.0/255.0, alpha: 1.0).cgColor
let shapeLayer:CAShapeLayer = CAShapeLayer()
let shapeRect = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height)
shapeLayer.bounds = shapeRect
shapeLayer.position = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2)
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = color
shapeLayer.lineWidth = 2
shapeLayer.lineJoin = CAShapeLayerLineJoin.round
shapeLayer.lineDashPattern = [6,3]
shapeLayer.path = UIBezierPath(roundedRect: shapeRect, cornerRadius: 4).cgPath
self.layer.addSublayer(shapeLayer)
}
我在从 nib 的 awake 中调用这个函数,如下所示:
view.addDashedBorder().
【问题讨论】:
标签: ios swift xcode uitableview