ios - SwiftUI 如何将 contextMenu 添加到列表行中的图像并保持圆角并且不显示整行?
问题描述
我有一个.listStyle(InsetGroupedListStyle())
风格的 SwiftUI 列表。在此列表中,我在一个部分中有一些图像。
我想contextMenu
在图像中添加一个。但是,它可以正常工作,而不是仅显示contextMenu
附加的图像 - 显示整行,并且仅在该部分的顶部或底部行上圆角。
如何contextMenu
仅显示图像,以及如何在所有情况下为所有角落获得圆角?
List {
Section {
// In this top row only the top two corners have rounded corners.
Image("topImage")
.resizable()
.scaledToFit()
.frame(width: 100, height: 100)
.contentShape(RoundedRectangle(cornerRadius: 16, style: .continuous)) // this has no effect
.contextMenu(ContextMenu(menuItems: {
Button {
Text("Button")
} label: {
HStack {
Text("Button Action")
}
}
}))
// In this middle row none of the corners have rounded corners
Image("middleImage")
.resizable()
.scaledToFit()
.frame(width: 100, height: 100)
.contentShape(RoundedRectangle(cornerRadius: 16, style: .continuous)) // this has no effect
.contextMenu(ContextMenu(menuItems: {
Button {
Text("Button")
} label: {
HStack {
Text("Button Action")
}
}
}))
// In this bottom row only the bottom corners have rounded corners
Image("bottomImage")
.resizable()
.scaledToFit()
.frame(width: 100, height: 100)
.contentShape(RoundedRectangle(cornerRadius: 16, style: .continuous)) // this has no effect
.contextMenu(ContextMenu(menuItems: {
Button {
Text("Button")
} label: {
HStack {
Text("Button Action")
}
}
}))
}
}
.listStyle(InsetGroupedListStyle())
解决方案
推荐阅读
- javascript - 为傅里叶变换绘图制作路径
- amazon-web-services - Aws - acm 证书绑定到 ec2 实例
- python - 如何使用探针在 python 中创建 gstreamer 管道
- matlab - 如何根据值返回行
- vba - 如何按特定字符串对单词表进行排序,这是第一列每行内的 HH:MM 时间
- fullcalendar - 带有垂直天标题的 resourceDayGrid
- python - 如何计算两个日期之间的日期出现
- python - 是否可以在 Python 中将 Gensim 包用于非英语语言?
- android - 为什么我的五彩纸屑来自 Android 屏幕的角落
- wpf - WPF Prism Dialog Service WindowStartupLocation 未重新计算位置