また1からこつこつと

最高はひとつじゃないと信じてまたがんばります。

【Swift3】 UITableViewのHeaderをカスタマイズする方法

今開発中のアプリでUITableViewのHeaderをイジる必要があって、いろいろ調べたのでメモ。

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
 //code
}

ではなくて、viewForHeaderInSectionを使ってUIViewをリターンしてあげる。

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
 let headerView:UIView = UIView()
 headerView.backgroundColor = UIColor.white
 return headerView
}

あとはこのViewにいろいろと追加していけば好みのものがつくれる。

headerの高さは、tableViewのメソッドで指定する。

tableView.sectionHeaderHeight = CGFloat()

仕事でコード書くと知らないことを知れるのでおもしろい。
いろいろと勉強になる。