Remove separator line for only one cell

后端 未结 13 2108
萌比男神i
萌比男神i 2020-12-30 19:38

I\'m trying to remove the separator for one UITableViewCell. I did the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellFo         


        
相关标签:
13条回答
  • 2020-12-30 19:50

    If you'd like to show separator to only the visible cell you can try this:

    tableView.separatorInset = UIEdgeInsets(top: 0, left: 1000, bottom: 0, right: 0)
    
    let visibleCell = tableView.visibleCells
    
        for cellV in visibleCell{
            cellV.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        }
    
    0 讨论(0)
  • 2020-12-30 19:50

    Swift 3 remove separator all cell:

     override func viewDidLoad() {
            self.yourTableView.separatorStyle = UITableViewCellSeparatorStyle.none
        }
    
    0 讨论(0)
  • 2020-12-30 19:51

    Just add following to the cell you don't want separator (swift 3) :

    override func awakeFromNib() {
        super.awakeFromNib()
    
        // remove separator
        self.separatorInset = UIEdgeInsetsMake(0, 1000, 0, 0)
    }
    
    0 讨论(0)
  • 2020-12-30 19:53

    You can just visually hide separator through separatorInset property:

    tableViewCell.separatorInset = UIEdgeInsets(top: 0, left: 10000, bottom: 0, right: 0)
    
    0 讨论(0)
  • 2020-12-30 19:53

    For those people struggling with this for iOS 9 the solution is a little different than the answers already given. Here is how I solved it in Swift:

    override func viewWillAppear(animated: Bool) {
        table.cellLayoutMarginsFollowReadableWidth = false
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        if IS_THE_CELL_WITH_NO_SEPARATOR{
            cell.separatorInset = UIEdgeInsetsZero
            cell.preservesSuperviewLayoutMargins = false
            cell.layoutMargins = UIEdgeInsetsZero
        }
    }
    
    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if IS_THE_CELL_WITH_NO_SEPARATOR{
            let size = self.view.bounds.size
            let rightInset = size.width > size.height ? size.width : size.height
            cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, rightInset)
        }
    }
    
    0 讨论(0)
  • 2020-12-30 19:54

    Swift 4

    iOS 11

    Assign next values for specific cell you need for customization.

    cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, .greatestFiniteMagnitude)
    cell.directionalLayoutMargins = .zero
    
    0 讨论(0)
提交回复
热议问题