6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【SwiftUI】contextMenuの形を変える方法

Last updated at Posted at 2023-06-23

はじめに

contextMenuの形を変える方法を紹介します。

作るもの

カプセル型のcontextMenuを作ります。
スクリーンショット 2023-06-23 23.02.34.png

やり方

contentShapeの第一引数にcontextMenuPreviewを指定し、第二引数に好きな形を指定すると、contextMenuの形を変えることができます。

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .contentShape(.contextMenuPreview, Capsule())
            .contextMenu {
                Button("Button") {}
            }
    }
}

まとめ

contentShapeを使うと、contextMenuの形を変えることができます。カプセルの他にも、円や四角形など、様々な形を指定できます。

参考文献

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?