Notice
Recent Posts
Recent Comments
Link
ยซ   2024/07   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

lgvv98

[SwiftUI] Alert ๋ณธ๋ฌธ

apple/๐Ÿš SwiftUI & Combine

[SwiftUI] Alert

๐Ÿฅ• ์บ๋Ÿฟ๋งจ 2022. 5. 18. 15:54

Alert

 

โœ… SwiftUI์—์„œ Alert๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์•Œ์•„๋ณด์ž.

์•„์ฃผ ๊ฐ„๋‹จํ•œ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ปค์Šคํ…€ ํ•˜๋Š” ๊ฒƒ์€ ์•Œ์•„์„œ ํ•ด๋ณด๊ธฐ!

import SwiftUI

struct contentView: View { 
	
    // struct๋Š” class์™€ ๋‹ค๋ฅด๊ฒŒ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ณ ์ •์ด๋ผ์„œ ๋ณ€๊ฒฝ์„ ํ•˜๋ ค๋ฉด @stateํ‚ค์›Œ๋“œ ์‚ฌ์šฉ
    // mutating๊ณผ ๋‹ฎ์•„์žˆ๋‹ค.
	@State var shouldShowAlert: Bool = false

	var body: some View { 
    	 Button(
         	action: {
         		print("ํ™•์ธ ๋ฒ„ํŠผ์ด ํด๋ฆญ๋˜์—ˆ๋‹ค.")
            	self.shouldShowAlert = true 
            }) {
            		Text("ํ™•์ธ")
                    .fontWeight(.bold)
                    
                    .foregroundColor(.white)
                    .padding()
                    .frame(width: 80)
                    .background(Color.blue)
                    .cornerRadius(20)
                }.alert(isPresented: $shouldShowAlert) { // binding์ด๋ฏ€๋กœ ๋‹ฌ๋Ÿฌ์‹ธ์ธ!
                    Alert(title: Text("์•Œ๋ฆผ์ฐฝ์ž…๋‹ˆ๋‹ค!"))
                }
    }
}

๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์•Œ๋ฆผ์ฐฝ์ด ๋‚˜ํƒ€๋‚œ๋‹ค.

'apple > ๐Ÿš SwiftUI & Combine' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[SwiftUI] NavigationView  (0) 2022.05.18
[SwiftUI] List (tableView in UIKit)  (0) 2022.05.18
[SwiftUI] VStack, HStack, ZStack  (0) 2022.05.18
[SwiftUI] How to set Image in SwiftUI  (0) 2022.05.18
[SwiftUI] Info.plist๊ฐ€ ์—†์„ ๋•Œ๐Ÿค”  (0) 2022.02.23
Comments