[UIKit] 테이블뷰 섹션 타이틀 폰트 설정
2023. 5. 5. 20:54ㆍiOS/UIKit
728x90
반응형
🧸 시작
![]() |
![]() |
변경 전 | 변경 후 |
🧸 코드
var tableViewSectionHeader = ["즐겨찾기", "내 주변 병원"]
extension HomeViewController: UITableViewDelegate, UITableViewDataSource {
//섹션의 개수
func numberOfSections(in tableView: UITableView) -> Int {
return tableViewSectionHeader.count
}
//섹션의 타이틀 텍스트
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return tableViewSectionHeader[section]
}
//섹션의 타이틀 텍스트 폰트 설정
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let titleLabel = UILabel()
titleLabel.frame = CGRect(x: 20, y: 8, width: 320, height: 30)
titleLabel.font = UIFont.boldSystemFont(ofSize: 24)
titleLabel.textColor = UIColor(named: "COLOR_PURPLE")
titleLabel.text = self.tableView(tableView, titleForHeaderInSection: section)
titleLabel.textAlignment = .left
let headerView = UIView()
headerView.backgroundColor = .white
headerView.addSubview(titleLabel)
return headerView
}
//섹션의 타이틀 높이 설정
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
...
}
728x90
반응형
'iOS > UIKit' 카테고리의 다른 글
[UIkit] Xcode pbxproj 충돌 해결방법 (0) | 2024.05.20 |
---|---|
[UIKit] Thread 16: "*** +[NSURLComponents setPercentEncodedQueryItems:]: invalid characters in percentEncodedQueryItems" (0) | 2023.05.06 |
[UIKit] Thread 1: "-[NSLayoutConstraint center]: unrecognized selector sent to instance 0x6000030d12c0" (0) | 2023.04.06 |
[UIKit] info파일 이동하기 (0) | 2023.03.29 |
[UIKit] 웹이미지 다운받기(비동기 처리) -Closure, RxSwift (0) | 2023.03.05 |