티스토리 뷰
iOS
iOS) UISheetPresentationController - Custom Detents로 Sheet 높이 설정하기(WWDC2022)
Ekko0701 2022. 10. 14. 00:06기존 UISheetPresentationController에는 Detents가. medium과. large 뿐이었다.
iOS16부터는 Custom Detents를 이용해 Sheet의 높이를 직접 설정해줄 수 있게 되었다.
직접 해보자. WWDC2022 What's new in UIKit을 참고했다.
높이 200인 Detent를 detents배열에 추가해 주었다.
sheet.detents = [
.custom{ _ in
200.0
}
]
최대 높이를 기준으로 높이를 설정할수도있다.
sheet.detents = [
.custom{ context in
0.3 * context.maximumDetentValue
}
]
Custom Detent에 identifier를 줘서 sheet의 다른 프로퍼티에서 사용할 수도 있다.
extension UISheetPresentationController.Detent.Identifier {
static let small = UISheetPresentationController.Detent.Identifier("small")
}
// Get a sheet
if let sheet = sheetView.sheetPresentationController {
//Customize the sheet
sheet.detents = [
.custom(identifier: .small){ context in
0.3 * context.maximumDetentValue
}
]
sheet.largestUndimmedDetentIdentifier = .small
}
identifier를 이용해 직접 Detent를 생성해서 사용할 수도 있다.
// Create Detent
let smallDetent = UISheetPresentationController.Detent.custom(identifier: .small) { context in
return 20
}
// Get a sheet
if let sheet = sheetView.sheetPresentationController {
//Customize the sheet
sheet.detents = [
.large(),
smallDetent
]
}
'iOS' 카테고리의 다른 글
iOS) Error 추가 - Add Transport Security has blocked a cleartext HTTP connection to { ~ } since it is insecure .. (0) | 2022.10.19 |
---|---|
iOS) 프로젝트에 폰트 적용하기 (1) | 2022.10.14 |
iOS) Buttom Sheet - UISheetPresentationController (0) | 2022.10.13 |
iOS) Carousel Effect 배너 구현하기 (Card 레이아웃, 자동 스크롤) with UICollectionView (0) | 2022.10.12 |
iOS) UICollectionView Programmatically (0) | 2022.10.10 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Sheet Height
- sheetPresentationController
- Custom Detent
- crud
- CAGradientLayer
- Gradient View
- UICollectionView Error
- 2023 회고
- Carousel Effect
- 요시푸스
- github
- autolayout
- UICollectionView banner
- BOJ 10820
- git
- Algorithm
- Card CollectionVIew
- BOJ 17298
- 1406 에디터
- ios
- BOJ 10808
- bottom sheet
- BOJ 10809
- NaverMaps
- BOJ 10799
- BOJ 10866
- BOJ 17413
- swift
- BOJ 1935
- Stack
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함