[iOS] tableView Header Height

Eugenie·2022년 7월 13일
0

tableView 내에는 Sections, Headers, Footers 가 존재한다.

평소에 나는 적당한 간격을 두어, 보기 좋게해야 한다는 생각을 가지고 있다.
앱을 만들면서 다음과 같은 상황이 발생했다.

'물마시기' 라는 타이틀과
'물 마실 시간'이라는 tableView 의 header 사이의 간격이 좁게 느껴진다.

UITableView 의 Delegate 중,
tableView(_:heightForHeaderInSection:) 로 해결할 수 있었다.

tableView(_:heightForHeaderInSection:)

optional func tableView(
    _ tableView: UITableView,
    heightForHeaderInSection section: Int
) -> CGFloat

Parameters

🥏 tableView - 정보를 요청하는 테이블 뷰
🥏 section - 테이블 뷰의 섹션을 식별하는 인덱스 번호
Return Value - section header 의 높이를 지정하는 음수가 아닌 부동소수점 값
// header 너비 조정으로 title 과의 간격 조정
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 30.0
    }

다음은 위의 코드를 적용한 결과이다.

이전의 상태보다 좀 더 보기 좋아진 것을 알 수 있다.


📚 Reference
Setting tableView header's height in Swift
tableView(_:heightForHeaderInSection:)
[iOS] Sections, Headers, Footers in TableView

profile
🌱 iOS developer

0개의 댓글