3
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】アラートにテキストフィールドを付ける

Posted at

はじめに

SwiftUIでアラートにテキストフィールドを付ける方法を記事にしておきます。

実装

import SwiftUI

struct ContentView: View {
    @State private var isPresented = false
    
    @State private var text = ""
    
    var body: some View {
        Button {
            isPresented = true
        } label: {
            Text("アラートを表示")
        }
        .alert("アラート", isPresented: $isPresented) {
            TextField("テキストフィールド", text: $text)
            
            Button {
                print("OK")
            } label: {
                Text("OK")
            }
        }
    }
}

Simulator Screenshot - iPhone 14 - 2023-06-02 at 22.39.38.png

おわり

いい感じにできました!

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