gpt4 book ai didi

swift - SwiftUI 中的圆角边框

转载 作者:行者123 更新时间:2023-12-03 09:18:50 47 4
gpt4 key购买 nike

如何在 SwiftUI 中圆形边框?

我认为这会起作用:

.cornerRadius(10)
.border(Color.white)

它不起作用。

这是我现在的解决方法:
.overlay(RoundedRectangle(cornerRadius: 10).stroke(lineWidth: 1).foregroundColor(.white))

最佳答案

这不是解决方法,而是您在 SwiftUI 中的处理方式。两件事情:

  • 曾经有一个 cornerRadius在……beta 4 中被弃用的修饰符?测试版 5?是的,它一直是一个移动的目标。
  • 很棒 非常感谢@kontiki ( blog post ),这是一个很好地返回你想要的扩展:
     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/

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