Rob*_*ert 9 contextmenu swiftui
我创建了一个照片库,每个单元格中都有包含许多单元格的列表。有几个UIImages。我添加了图像的 contextMenu ,但是当我长按每个图像时,将调用整个单元格而不是每个图像。谁能帮助我如何将 contextMenu 添加到列表中的每个项目
struct PhotoList : View {
var photoLibrary = PhotoLibrary
var body : some View {
GeometryReader { geometry in
List(self.photoLibrary, id: \.self) { imageSet in
HStack (alignment: .center) {
ForEach(imageSet, id: \.self) { image in
Image(uiImage: image)
.scaledToFill()
.cornerRadius(7)
.padding(3)
.frame(width: 150, height: 150, alignment: .center)
.contextMenu {
VStack {
Button(action: {}) {
HStack {
Text("Add to Today")
Image("plus.circle")
}
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
小智 -4
据我所知,上下文菜单必须至少有两个按钮,但我认为以下方式就足够了:
Image(uiImage: image)
.scaledToFill()
.cornerRadius(7)
.padding(3)
.frame(width: 150, height: 150, alignment: .center)
.contextMenu {
Button(action: {}) {
Text("Add to Today")
Image("plus.circle")
}
Button(action: {}) {
Text("Some Other Button")
Image("globe")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2303 次 |
| 最近记录: |