【问题标题】:ContextMenu on a rounded LinearGradient produces sharp edges in SwiftUI圆形 LinearGradient 上的 ContextMenu 在 SwiftUI 中产生锐利的边缘
【发布时间】:2020-07-05 14:20:39
【问题描述】:

我有以下看法:

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 时,边缘不圆:

我已经尝试了几件事,例如:

  • 应用clipShape 修饰符将其剪辑到RoundedRectangle
  • 将渐变包装为 RoundedRectangle 视图的背景
  • 使用 Color 而不是 LinearGradient(按预期工作,但不是我需要的)

但是没有一个工作。任何建议将不胜感激,谢谢!

【问题讨论】:

    标签: swift view swiftui contextmenu gradient


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2023-02-06
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      相关资源
      最近更新 更多