LoginSignup
31
23

More than 5 years have passed since last update.

Grouped UITableView のセクションヘッダーおよびフッターの余白をなくす方法

Posted at

要件

UITableView を Grouped Style にした際、このような余白がヘッダーとフッターの領域にできてしまいます。これを無くしたいです。

イメージ

対応

UITableViewDelegate からセクションヘッダーおよびフッターの高さ値を返しますが、ここで CGFloat.leastNormalMagnitude という具合で高さ値を指定してあげれば、例の余白をなくすことができます。

ちなみに return 0.0 や、tableView.sectionFooterHeight = CGFloat.leastNormalMagnitude では効果がありませんでした。

UITableViewDelegate
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
}
結果
31
23
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
23