我想使用帶有圓形按鈕的 ContextMenu。如果通過長按激活 ContextMenu,則會在按鈕周圍出現一個圓角矩形形狀的陰影。我已經嘗試過使用.contentShape(Circle()),但這根本不起作用。
有沒有辦法隱藏這個陰影或改變它的形狀,使其與按鈕相匹配?也許可以修改底層 UIKit 視圖的屬性?
謝謝回答!

import SwiftUI
struct ContentView: View {
var body: some View {
Circle()
.frame(width: 100, height: 100, alignment: .center)
.foregroundColor(.yellow)
.contentShape(Circle()) //does not work
.contextMenu
{
Button(action: {}, label:
{
Text("Action 1")
})
Button(action: {}, label:
{
Text("Action 2")
})
}
}
}
uj5u.com熱心網友回復:
您需要為背景關系選單預覽設定 contentMenu 形狀。
你可以這樣做:
.contentShape(.contextMenuPreview, Circle())
您可以在Apple Developer Documentation上閱讀相關內容
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/415451.html
標籤:
