【发布时间】:2021-01-30 07:34:15
【问题描述】:
我正在尝试在上下文菜单中添加删除操作,但它只是显示为默认的黑色。照片应用程序也使用红色进行删除操作。我在网上的一些空间看到这不是contextMenu 当前提供的功能,但是我也看到它在野外here 中使用了它。有谁知道如何做到这一点?
此外,在 Apple 的 documentation 中查看 contextMenu 时,它表示它们已被弃用,除了 macOS。我觉得很奇怪,他们在引入它一年后就弃用了它。这是否被我应该使用的另一个组件替换?
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(photos) { photo in
Image(uiImage: UIImage(data: photo.imageData!)!)
.resizable()
.aspectRatio(1, contentMode: .fill)
.contextMenu(menuItems: {
Button(action: {
deletePhoto(selectedPhoto: photo)
}) {
Label("Remove", systemImage: "trash")
}
})
}
}
.padding()
.navigationBarTitle(Text("Albums"))
.navigationBarItems(trailing:
Button(action: {
self.showingImagePicker = true
}) {
Image(systemName: "plus.circle.fill")
}
)
.sheet(isPresented: $showingImagePicker, onDismiss: loadImage) {
ImagePicker(image: self.$inputImage)
}
}
}
【问题讨论】: