如何在 SwiftUI 中圆形边框?
我认为这会起作用:
.cornerRadius(10)
.border(Color.white)
它不起作用。
这是我现在的解决方法:
.overlay(RoundedRectangle(cornerRadius: 10).stroke(lineWidth: 1).foregroundColor(.white))
最佳答案
这不是解决方法,而是您在 SwiftUI 中的处理方式。两件事情:
cornerRadius
在……beta 4 中被弃用的修饰符?测试版 5?是的,它一直是一个移动的目标。 extension View {
public func addBorder<S>(_ content: S, width: CGFloat = 1, cornerRadius: CGFloat) -> some View where S : ShapeStyle {
let roundedRect = RoundedRectangle(cornerRadius: cornerRadius)
return clipShape(roundedRect)
.overlay(roundedRect.strokeBorder(content, lineWidth: width))
}
}
用法:
.addBorder(Color.white, width: 1, cornerRadius: 10)
关于swift - SwiftUI 中的圆角边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57753997/