반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- RxSwift
- Observable
- Android
- ios
- UIButton
- UITabBarController
- dictionary
- SwiftUI
- WebView
- gcd
- 웹뷰
- subscript
- SwiftLint
- NavigationLink
- Alamofire
- autolayout
- Firebase
- 라이트모드
- string
- 문자열
- Realtime Database
- 다크모드
- swipe
- Java
- Apple
- remote config
- github
- LazyHStack
- UIScrollView
- Swift
Archives
- Today
- Total
점진적 과부하 개발 블로그
SwiftUI Alert 알아보기 본문
반응형
SwiftUI Alert 알아보기
UIKit & SwiftUI 비교
- UIKit
- 커스텀에 더 유용한 것 같다.
- UIAlertController와 UIAlertAction을 이용해서 구현한 코드
@IBAction func tapAddButton(_ sender: UIBarButtonItem) {
let alert = UIAlertController(title: "타이틀", message: nil, preferredStyle: .alert)
let registerButton = UIAlertAction(title: "확인", style: .default, handler: { [weak self] _ in
guard let title = alert.textFields?[0].text else { return }
let task = Task(title: title, done: false)
self?.tasks.append(task)
self?.tableView.reloadData()
})
let cancelButton = UIAlertAction(title: "취소", style: .cancel, handler: nil)
alert.addTextField(configurationHandler: { textField in
textField.placeholder = "placeHolder."
})
alert.addAction(cancelButton)
alert.addAction(registerButton)
self.present(alert, animated: true, completion: nil)
}
- SwiftUI
- 굉장히 직관적으로 코드를 짤수가 있다.
- 하지만 아직 호환성이 좋지가 않다,
struct ContentView: View {
@State private var presentAlert = false
var body: some View {
NavigationView {
List {
Text("ToDoList")
}
.navigationBarTitle(Text("ToDoList"))
.navigationBarItems(
trailing:
Button(
action: {
self.presentAlert = true
},
label: {
Image(systemName: "plus.circle")
}
)
.alert("타이틀", isPresented: $presentAlert, actions: {
Button("확인", action: {})
Button("취소", role: .cancel, action: {})
})
)
}
}
}
반응형
'Swift' 카테고리의 다른 글
Swift Lazy Stored Properties (지연 저장된 프로퍼티) (0) | 2022.06.26 |
---|---|
Swift 콜렉션 타입(Collection Types) (0) | 2022.06.23 |
Swift Combine을 사용한 데이터 표시 구현 (0) | 2022.06.18 |
SwiftUI NavigationView 알아보기 (0) | 2022.06.17 |
Swift HStack (0) | 2022.06.12 |