【发布时间】:2021-05-25 23:27:55
【问题描述】:
我想将clipShape 修饰符应用于只有左上角和左下角圆角的圆角矩形。
我正在使用this extension 对我拥有的某些视图的特定角进行圆角处理。
所以,如果我能做到这一点,我会很高兴:
.clipShape(Rectangle().cornerRadius(20, [.topLeft, .topRight]))
但我收到错误说 Rectangle must be a shape...
所以我想我必须创建类似的东西:
struct RectangleX: Shape {
func path(in rect: CGRect) -> Path {
var radius = CGFloat.infinity
var corners = UIRectCorner.allCorners
let path = UIBezierPath(roundedRect: rect,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius,
height: radius))
return Path(path.cgPath)
}
}
但我看不到如何将矩形传递给它。
【问题讨论】: