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

后端 未结 14 930
礼貌的吻别
礼貌的吻别 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
    }
    
    0 讨论(0)
  • 2020-12-29 03:19

    I used the table view style "grouped" to add this line:

    And furthermore it avoids sticking the last separator line to stick on the screen when scrolling out!

    0 讨论(0)
提交回复
热议问题