【发布时间】:2022-11-11 07:40:57
【问题描述】:
我正在尝试向视图添加边框并仅围绕 topLeading 和 topTrailing 角。似乎很难实现?使用此扩展程序很容易绕过角落:
struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
}
}
extension View {
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape( RoundedCorner(radius: radius, corners: corners) )
}
}
【问题讨论】:
标签: swiftui