gpt4 book ai didi

swiftui - 如何在我的自定义形状上圆化这些角?

转载 作者:行者123 更新时间:2023-12-02 18:03:42 28 4
gpt4 key购买 nike

我制作了一个自定义的“倾斜”矩形,我想将其变成圆角“倾斜”矩形。这是迄今为止的图片:

shape

struct SlantedRectangle: Shape {
func path(in rect: CGRect) -> Path {
return Path { path in
path.move(to: CGPoint(x: rect.width, y: 30))
path.addLine(to: CGPoint(x: rect.width, y: rect.height))
path.addLine(to: CGPoint(x: 0, y: rect.height))
path.addLine(to: CGPoint(x: 0, y: 0))
}
}
}

如何将左上角和右上角圆角化?

最佳答案

对于圆角,您可以使用 addArc Path 的方法。

struct SlantedRectangle: Shape {
let slanted: CGFloat
let radius: CGFloat

func path(in rect: CGRect) -> Path {
return Path { path in
path.move(to: CGPoint(x: rect.width - radius, y: slanted))
path.addArc(center: CGPoint(x: rect.width - radius, y: slanted + radius), radius: radius, startAngle: Angle(degrees: -90), endAngle: Angle(degrees: 0), clockwise: false)
path.addLine(to: CGPoint(x: rect.width, y: rect.height))
path.addLine(to: CGPoint(x: 0, y: rect.height))
path.addLine(to: CGPoint(x: 0, y: radius))
path.addArc(center: CGPoint(x: radius, y: radius), radius: radius, startAngle: Angle(degrees: 180), endAngle: Angle(degrees: 270), clockwise: false)
path.closeSubpath()
}
}
}

现在像这样创建您的SlantedRectangle

SlantedRectangle(slanted: 30, radius: 30)

Preview

关于swiftui - 如何在我的自定义形状上圆化这些角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73781039/

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