gpt4 book ai didi

ios - 在 Swift 中使用 UIBezierPath 添加两条路径

转载 作者:行者123 更新时间:2023-11-28 11:30:44 26 4
gpt4 key购买 nike

我使用 UIBezierPath 绘制了 2 条线,我如何组合点以形成字母 X 的形状。我想将两条线连接在一起

路径一

let path1 = UIBezierPath()
path1.move(to: .zero)
path1.addLine(to: CGPoint(x: 100, y: 100))
path1.close()
path1.lineWidth = 1.0
UIColor.blue.set()
path1.stroke()
path1.fill()

路径 2

let path2 = UIBezierPath()
path2.move(to: .zero)
path2.addLine(to: CGPoint(x: 50, y: 50))
path2.close()
path2.lineWidth = 1.0
UIColor.red.set()
path2.stroke()
path2.fill()

最佳答案

您应该使用正确的CGPoint

如果您的 View 边界值为 (0,0,100,100)

  • 移动到 (0,0)
  • 添加到 (100,100)
  • 模式为 (0,100)
  • 加线到 (100,0)

试试这个

let path = UIBezierPath()
path.move(to: .zero)
path.addLine(to: CGPoint(x: bounds.maxX, y: bounds.maxY))
path.move(to: CGPoint(x: bounds.minX, y: bounds.maxY))
path.addLine(to: CGPoint(x: bounds.maxX, y: bounds.minY))
path.close()
path.lineWidth = 1.0
UIColor.blue.set()
path.stroke()
path.fill()

关于ios - 在 Swift 中使用 UIBezierPath 添加两条路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56789138/

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