LoginSignup
0
1

【SwiftUI】macOSのアラートに表示されるアプリアイコンの箇所を好きな画像に変更する(macOS13)

Posted at

はじめに

macOS13からアラート(ダイアログ)のアイコン部分が変更できるようになりました。

こんな感じ

通常 今回の実装後
スクリーンショット 2024-01-04 20.23.41.png スクリーンショット 2024-01-04 20.23.08.png

実装

import SwiftUI

struct ContentView: View {
    @State private var isShowingDialog = false
    
    var body: some View {
        Button("Dialog") {
            isShowingDialog = true
        }
        .confirmationDialog("ダイアログ", isPresented: $isShowingDialog) {
            Button("Erase", role: .destructive) {
                // Handle item deletion.
            }
            Button("Cancel", role: .cancel) {
                isShowingDialog = false
            }
        }
+       .dialogIcon(Image(.icon))
    }
}

アラートでも機能します。

.alert("アラート", isPresented: $isShowingAlert) {
    Button("Erase", role: .destructive) {
        // Handle item deletion.
    }
    Button("Cancel", role: .cancel) {
        isShowingDialog = false
    }
}
.dialogIcon(Image(.icon))

おわり

これ今までできなかったんですね

公式ドキュメント

0
1
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
0
1