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
- Clean Code
- MVVM
- 클린 코드
- Human interface guide
- HIG
- collectionview
- rxswift
- 리펙토링
- combine
- Refactoring
- 리팩토링
- ribs
- UITextView
- RxCocoa
- swift documentation
- Observable
- Protocol
- UICollectionView
- 스위프트
- map
- Xcode
- 애니메이션
- swiftUI
- ios
- 리펙터링
- tableView
- uiscrollview
- clean architecture
- uitableview
- SWIFT
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] UITableView 하단 inset이 자동으로 34로 설정 방지 방법 (contentInsetAdjustmentBehavior) 본문
iOS 응용 (swift)
[iOS - swift] UITableView 하단 inset이 자동으로 34로 설정 방지 방법 (contentInsetAdjustmentBehavior)
jake-kim 2024. 3. 20. 01:23tableView에 자동으로 설정되는 inset
- contentInsetAdjustmentBehavior 값은 os에서 자동으로 safe area를 고려하여 설정되는 getter 프로퍼티
open class UIScrollView : UIView, NSCoding, UIFocusItemScrollableContainer {
@available(iOS 11.0, *)
open var adjustedContentInset: UIEdgeInsets { get }
...
}
- 이 값을 직접 set해줄수는 없기 때문에 "contentInsetAdjustmentBehavior"를 사용하여 조절이 가능
open class UIScrollView : UIView, NSCoding, UIFocusItemScrollableContainer {
/* Configure the behavior of adjustedContentInset.
Default is UIScrollViewContentInsetAdjustmentAutomatic.
*/
@available(iOS 11.0, *)
open var contentInsetAdjustmentBehavior: UIScrollView.ContentInsetAdjustmentBehavior
...
}
- 이 값의 default는 automatic이므로 아무런 설정을 해주지 않으면 scrollView의 bottom, top inset값이 자동으로 조절되는 것
- never로 설정해주면 자동으로 변경 x
@available(iOS 11.0, *)
public enum ContentInsetAdjustmentBehavior : Int, @unchecked Sendable {
case automatic = 0 // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
case scrollableAxes = 1 // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
case never = 2 // contentInset is not adjusted
case always = 3 // contentInset is always adjusted by the scroll view's safeAreaInsets
}
예시)
- tableView 준비
private let tableView = {
let view = UITableView()
view.register(MyCell.self, forCellReuseIdentifier: "cell")
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
- tableView 레이아웃
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
view.addSubview(tableView)
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
tableView.topAnchor.constraint(equalTo: view.topAnchor),
])
}
- viewDidAppear에서 adjustedContentInset을 출력해보면 상단에 59.0, 하단에 34.0이 존재
print(tableView.adjustedContentInset)
// UIEdgeInsets(top: 59.0, left: 0.0, bottom: 34.0, right: 0.0)
- contentInsetAdjustmentBehavior값을 never로 설정
private let tableView = {
let view = UITableView()
view.register(MyCell.self, forCellReuseIdentifier: "cell")
view.contentInsetAdjustmentBehavior = .never // <-
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
- adjustedContentInset값이 모두 0으로 된 것을 확인
* 전체 코드: https://github.com/JK0369/ExLabelStaticHeight
* 참고
- https://developer.apple.com/documentation/uikit/uiscrollview/2902261-contentinsetadjustmentbehavior
'iOS 응용 (swift)' 카테고리의 다른 글
Comments