iOS 8 UITableView separator inset 0 not working

前端 未结 30 1765
清酒与你
清酒与你 2020-11-22 14:38

I have an app where the UITableView\'s separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.

30条回答
  •  感情败类
    2020-11-22 15:25

    Simple solution in Swift for iOS 8 with a custom UITableViewCell

    override func awakeFromNib() {
        super.awakeFromNib()
    
        self.layoutMargins = UIEdgeInsetsZero
        self.separatorInset = UIEdgeInsetsZero
    }
    

    In this way you are setting layoutMargin and separatorInset just one time instead of doing it for each willDisplayCell as most of the above answers suggest.

    If you are using a custom UITableViewCell this is the correct place to do it. Otherwise you should do it in tableView:cellForRowAtIndexPath.

    Just another hint: you don't need to set preservesSuperviewLayoutMargins = false because default value is already NO!

提交回复
热议问题