设置tableView的分割线填满cell的方式总结

方式一:cell的底部添加一个UIView

  • 1.在tableViewController的viewDidLoad中取消系统的分割线
      // 取消系统的分割线
      self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
  • 2.在自定义cell的底部添加一个UIView,高度设置为1,并设置颜色,如果感觉分割线过于明显,可以修改透明度。 

方式二:设置cell的separatorInset和layoutMargins属性

  • 在cell的类文件中设置separatorInset和layoutMargins这两个属性即可
    • 注意:layoutMargins属性是从iOS8以后才有的,所以此种方法给在iOS8以后才可以使用
      self.separatorInset = UIEdgeInsetsZero;
      self.layoutMargins = UIEdgeInsetsZero;
      

方式三:

  • 1.在tableViewController的viewDidLoad中取消系统的分割线,并设置背景色
    // 取消系统的分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    // 设置背景色
    self.tableView.backgroundColor = [UIColor colorWithRed:206 / 255.0 green:206 / 255.0 blue:206 / 255.0 alpha:1];
    
  • 2.重写cell的setFrame方法,将cell的高度减1

- (void)setFrame:(CGRect)frame {
    // cell高度减1
    frame.size.height -= 1;
    // 设置frame
    [super setFrame:frame];
}
原文地址:https://www.cnblogs.com/mengfei90/p/5210478.html