【发布时间】:2019-05-31 12:27:18
【问题描述】:
我已经创建了一些自定义层并添加到 UIView 上,我有两个 CAShaper 层但我在这里只展示一个示例
hexBorderOtline = CAShapeLayer()
hexBorderOtline.name = "dhiru_border_hidden"
hexBorderOtline.path = path2.cgPath
hexBorderOtline.lineCap = .round
hexBorderOtline.strokeColor = inActiveBorderColor.cgColor
hexBorderOtline.fillColor = UIColor.clear.cgColor
self.layer.addSublayer(hexBorderOtline)
我想在点击按钮时改变它的边框颜色。
func btnAction()
{
hexBorderOtline.strokeColor = activeBorderColor.cgColor
}
但这不起作用,我发布了一张参考图片,我需要点击按钮。
【问题讨论】:
-
hexBorderOtline 是如何定义的?
-
我已经添加了代码,我如何初始化
var hexBorderOtline:CAShapeLayer!` -
hexBorderOtline 必须是全局变量,并在主线程上使用 hexBorderOtline.strokeColor = UIColor.blue.cgColor 更改按钮的颜色。我刚刚尝试并且可以工作,如果不起作用,您会丢失对象的引用或在新线程中工作,请确保您在主线程上。
标签: ios swift uibezierpath cashapelayer