如何在 SwiftUI 中圆化边框?
我认为这会起作用:
.cornerRadius(10)
.border(Color.white)
但它不起作用。
这是我现在的解决方法:
.overlay(RoundedRectangle(cornerRadius: 10).stroke(lineWidth: 1).foregroundColor(.white))
这不是解决方法,而是在 SwiftUI 中执行此操作的方法。两件事情:
-
曾经有一个cornerRadius
在 beta 4 中已弃用的修饰符?测试版5?是的,这是一个移动的目标。
-
With a great非常感谢@kontiki (博客文章 https://swiftui-lab.com/view-extensions-for-better-code-readability/),这是一个可以很好地返回您想要的内容的扩展:
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))
}
}
Usage:
.addBorder(Color.white, width: 1, cornerRadius: 10)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)