gpt4 book ai didi

swift - 圆形 LinearGradient 上的 ContextMenu 在 SwiftUI 中产生锐边

转载 作者:行者123 更新时间:2023-12-03 09:19:00 24 4
gpt4 key购买 nike

我有以下观点:

struct ContentView: View {
var body: some View {
LinearGradient(gradient: Gradient(colors: [.blue, .red]), startPoint: .topTrailing, endPoint: .bottomLeading)
.cornerRadius(16)
.frame(width: 140, height: 140)
.contextMenu {
Button("", action: {})
}
}

}
但是,当 ContextMenu 被调用时,边缘不会被倒圆:
enter image description here
我尝试了几件事,例如:
  • 应用 clipShape 修饰符将其剪辑到 RoundedRectangle
  • 将渐变包装为 RoundedRectangle View 的背景
  • 使用颜色而不是 LinearGradient(按预期工作,但不是我需要的)

  • 然而没有工作。任何建议将不胜感激,谢谢!

    最佳答案

    .frame(...) 之后添加以下代码:

    .contentShape(RoundedRectangle(cornerRadius: 16, style: .continuous))

    关于swift - 圆形 LinearGradient 上的 ContextMenu 在 SwiftUI 中产生锐边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62741902/

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