圆形 LinearGradient 上的 ContextMenu 在 SwiftUI 中产生锐利的边缘
Posted
技术标签:
【中文标题】圆形 LinearGradient 上的 ContextMenu 在 SwiftUI 中产生锐利的边缘【英文标题】:ContextMenu on a rounded LinearGradient produces sharp edges in 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(按预期工作,但不是我需要的)
但是没有一个工作。任何建议将不胜感激,谢谢!
【问题讨论】:
【参考方案1】:在.frame(...)
之后添加如下代码:
.contentShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
【讨论】:
以上是关于圆形 LinearGradient 上的 ContextMenu 在 SwiftUI 中产生锐利的边缘的主要内容,如果未能解决你的问题,请参考以下文章