gpt4 book ai didi

ios - 如何快速设置 CAShapeLayer 的 strokeColor

转载 作者:行者123 更新时间:2023-12-01 21:59:43 28 4
gpt4 key购买 nike

我想绘制对角线 View 。

这是我的代码。

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

let path = UIBezierPath()
path.move(to: CGPoint.zero)
path.addLine(to: CGPoint(x: 50, y: 50))

let view = UIView(frame: CGRect(x: 100, y: 100, width: 50, height: 50))
view.backgroundColor = UIColor.blue

let mask = CAShapeLayer()
mask.frame = view.bounds
mask.path = path.cgPath
mask.strokeColor = UIColor.orange.cgColor
mask.lineWidth = 25

view.layer.mask = mask

self.view.addSubview(view)
}

我设置 strokeColororange .但是颜色是蓝色 backgroundColor
为什么会这样?

最佳答案

这是代码片段:

        let path = UIBezierPath()
path.move(to: CGPoint.zero)
path.addLine(to: CGPoint(x: 50, y: 50))

let view = UIView(frame: CGRect(x: 100, y: 100, width: 50, height: 50))
view.backgroundColor = UIColor.green

let diagonal = CAShapeLayer()
diagonal.frame = view.bounds
diagonal.path = path.cgPath
diagonal.strokeColor = UIColor.orange.cgColor
diagonal.lineWidth = 15
diagonal.backgroundColor = UIColor.blue.cgColor
// view.layer.mask = mask

view.layer.addSublayer(diagonal)

self.view.addSubview(view)

这导致:

enter image description here

关于ios - 如何快速设置 CAShapeLayer 的 strokeColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60369965/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com