티스토리 뷰
애플 HIG 에 ActionSheet는 "현재 컨텍스트와 관련된 두 개 이상의 선택 항목을 표시하는 특정 유형의 경고"라고 설명합니다.
iOS 에서 ActionSheet 는 UIAlertController를 이용해 만들 수 있습니다.
let actionSheetController
= UIAlertController(title: "제목", message: "메세지", preferredStyle: .actionSheet)
//제목, 메세지 없이
let actionSheetController
= UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
먼저 UIAlertController에서 actionSheet 스타일을 선택해 ActionSheet를 만듭니다.
*제목 또는 메시지가 없는 ActionSheet를 만들고싶으면 nil로 작성하면 됩니다! ""로 표현하면 빈 공간으로 나오더라구요...
let firstAction = UIAlertAction(title: "기능 1", style: .default, handler: {
//원하는 기능 구현
})
let secondAction = UIAlertAction(title: "기능2", style: .default, handler: {
//원하는 기능 구현
})
let destructiveAction = UIAlertAction(title: "destructive", style: .destructive, handler: nil)
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)
그 후 원하는 기능을 UIAlertAction로 만들어줍니다.
스타일은 일반 기능(default), 삭제 기능 등 (destructive) , 취소 기능 (cancel)이 있습니다.
각 기능의 handler를 통해 원하는 기능을 처리해 주면 됩니다.
하나의 ActionSheet에 취소 기능은 하나만 포함할 수 있습니다!
//Controller에 기능 추가
actionSheetController.addAction(firstAction)
actionSheetController.addAction(secondAction)
actionSheetController.addAction(destructiveAction)
actionSheetController.addAction(cancelAction)
//present로 Controller 호출
self.present(actionSheetController, animated: true, completion: nil)
맨 처음 만든 actionSheetController에, addAction을 이용해 기능을 추가해줍니다.
기능을 포함한 ActionSheetController는 present를 이용해 호출할 수 있습니다.
실행시키면 위처럼 액션 시트를 이용할 수 있게 됩니다!
* 전체코드
let actionSheetController
= UIAlertController(title: "제목", message: "메세지", preferredStyle: .actionSheet)
let firstAction = UIAlertAction(title: "기능 1", style: .default, handler: {
//원하는 기능 구현
})
let secondAction = UIAlertAction(title: "기능2", style: .default, handler: {
//원하는 기능 구현
})
let destructiveAction = UIAlertAction(title: "destructive", style: .destructive, handler: nil)
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)
actionSheetController.addAction(firstAction)
actionSheetController.addAction(secondAction)
actionSheetController.addAction(destructiveAction)
actionSheetController.addAction(cancelAction)
self.present(actionSheetController, animated: true, completion: nil)
참고:
https://developer.apple.com/design/human-interface-guidelines/ios/views/action-sheets/
https://developer.apple.com/documentation/uikit/uialertcontroller
'iOS > iOS 개발' 카테고리의 다른 글
iOS - BlendShapes 활용하기 (0) | 2021.05.27 |
---|---|
ARKit - BlendShapes (0) | 2021.05.25 |
iOS - Dispatch Queue (0) | 2021.05.21 |
iOS앱 Lottie 애니메이션 구현하기 (0) | 2020.11.29 |
XCODE프로젝트에 코코아팟(CocoaPods) 설치하기 (0) | 2020.11.29 |
- Total
- Today
- Yesterday
- disposeBag
- infallible
- C++
- cocoapods
- boj
- Neo4j
- 프로그래머스
- Lottie
- 안드로이드
- 백준
- rxswift
- Swift
- GraphDB
- 백준온라인저지
- Swift weak
- coreml
- 카카오인턴십
- SwiftUI
- blendshape
- Reactivex
- rxswift6
- ARKit
- blendshapes
- 알고리즘
- SWEA
- ios
- 코코아팟
- DispatchQueue
- Swift unowned
- Kotlin
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |