【发布时间】:2021-10-02 01:24:24
【问题描述】:
我目前正在尝试在我的 UIView 周围制作虚线边框。我参考了之前的一个帖子:Dashed line border around UIView
UIView 的左侧得到红色虚线,但右侧没有边缘。
这是我在 viewDidLoad 中执行的代码:
myview.backgroundColor = UIColor.lightGray
myview.layer.cornerRadius = 4
let dottedBorder = CAShapeLayer()
dottedBorder.strokeColor = UIColor.red.cgColor
dottedBorder.lineDashPattern = [4, 4]
dottedBorder.frame = myview.bounds
dottedBorder.fillColor = nil
dottedBorder.path = UIBezierPath(roundedRect: myview.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 4, height: 4)).cgPath
myview.layer.addSublayer(dottedBorder)
【问题讨论】:
-
关闭路径?
-
在 viewDidLayoutSubview 方法中也加入这一行:dottedBorder.frame = myview.bounds
-
@ElTomato 关闭路径是什么意思?
-
@RajaKishan 不,仍然没有覆盖整个视图
-
@infiniteObj 请参阅
UIBezierpath的文档。
标签: ios swift uiview uibezierpath cashapelayer