본문 바로가기
iOS Swift/Today I Learned

tableView의 header, footer view 색 변경하기

by 호두빵 2023. 1. 5.

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    if let header = view as? UITableViewHeaderFooterView {
        header.tintColor = ThemeManager.current.mainBackgroundColor
        header.textLabel?.textColor = ThemeManager.current.oppositeColor
    }
}

테이블뷰를 나누는 섹션의 텍스트컬러와 배경컬러는 view as? UITableViewHeaderFooterView를 통해서 배경색은 header.tintColor, 텍스트컬러는 header.textLabel.textColor를 통해 바꿀 수 있습니다.