UITableView: the proper way to display a separator for the last cell

后端 未结 14 1022
礼貌的吻别
礼貌的吻别 2020-12-29 02:23

The question is what\'s the right-most way to display a separator in the last cell in a table/section.

Basically this is what I am after.

14条回答
  •  甜味超标
    2020-12-29 03:18

    In iOS 8, if you have a plain style UITableView, and add a footer, the last separator is gone. However, you can easily recreate it by adding a custom separator view to the footer.

    This example exactly mimics Today Widget separator style

        override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    
            //create footer view
            let result = UIView()
            result.frame.size.height = tableView.rowHeight
    
            //recreate last cell separator, which gets hidden by footer
            let sepFrame = CGRectMake(15, -0.5, tableView.frame.width, 0.5);
            let vibrancyEffectView = UIVisualEffectView.init(effect: UIVibrancyEffect.notificationCenterVibrancyEffect())
            vibrancyEffectView.frame = sepFrame
            vibrancyEffectView.contentView.backgroundColor = tableView.separatorColor
            result.addSubview(vibrancyEffectView)
            return result
    }
    

提交回复
热议问题