5
3

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.

iOS強化月間 - iOSアプリ開発の知見を共有しよう -

【SwiftUI】Menuに赤いボタンを追加する

Last updated at Posted at 2023-10-02

はじめに

SwiftUIのMenu内に「削除」ボタンを実装しようとした時に、
削除ボタンの色は赤くしたかったのでtintやforgroundStyleなどで色変更しようとしてもできなかったので方法を記録しておきます。

実装

Buttonのルールを.destructiveにするとボタンが赤くなります

Menu {
    Button(role: .destructive) {
        // 処理
    } label: {
        Label("削除", systemImage: "trash")
    }
} label: {
    Image(systemName: "ellipsis")
}
.foregroundStyle(.secondary)

ダメな例

Menu {
    Button {
        // 処理
    } label: {
        Label("削除", systemImage: "trash")
    }
    .foregroundStyle(.red)
} label: {
    Image(systemName: "ellipsis")
}
.foregroundStyle(.secondary)

おわり

これ知らなかったです

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?