How to increase the UITableView separator height?

后端 未结 17 2125
花落未央
花落未央 2020-12-08 00:19

I want more space(10px) between each cell. How can I do this?

And I have added this code

tableView.separatorStyle = UITableViewCellSepar         


        
17条回答
  •  自闭症患者
    2020-12-08 01:00

    The best way for me, just add this in cellForRowAtIndexPath or in willDisplayCell

    CGRect sizeRect = [UIScreen mainScreen].applicationFrame;    
    NSInteger separatorHeight = 3;
    UIView * additionalSeparator = [[UIView alloc] initWithFrame:CGRectMake(0,cell.frame.size.height-separatorHeight,sizeRect.size.width,separatorHeight)];
    additionalSeparator.backgroundColor = [UIColor grayColor];
    [cell addSubview:additionalSeparator];
    

    For Swift 3.0:

    let screenSize = UIScreen.main.bounds
    let separatorHeight = CGFloat(3.0)
    let additionalSeparator = UIView.init(frame: CGRect(x: 0, y: self.frame.size.height-separatorHeight, width: screenSize.width, height: separatorHeight))
    additionalSeparator.backgroundColor = UIColor.gray
    self.addSubview(additionalSeparator)
    

    You should add this to cell's method awakeFromNib() to avoid re-creation.

提交回复
热议问题