LoginSignup
2

More than 1 year has passed since last update.

【Swift 4対応】UITableView (Grouped style) でのセパレータコントロール

Last updated at Posted at 2018-08-22

注意

UITableView に含まれるセパレータの役割を担う View は、 UITableViewCellSeparatorView という private な class です。この記事の方法は非推奨な方法となりますので、テクニックの一つとして御覧ください。

セクショングループの上下セパレータを非表示にする

Untitled.001.png

class SampleCell: UITableViewCell {
    override func layoutSubviews() {
        super.layoutSubviews()
        let targetName = "_UITableViewCellSeparatorView"
        for view in subviews {
            // グループの上下セパレータを非表示
            view.isHidden = view.frame.origin.x == 0 && NSStringFromClass(view.classForCoder) == targetName
        }
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        separatorView.isHidden = false
    }
}

本当は

上記のようなデザインを実現したい場合は、自分でセパレータを作ってコントロールするのが良さそうです。

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
2