Ios – Change tableView separator insets

celldelegatesiosuitableview

I'm incurred in a little problem customizing my cell;

enter image description here

as you can see the separator line do not reach the left border of the cell, and a I'd like to do it. I found these:

Can anyone help me to translate in swift code?

Best Answer

For conversion of the answer (Separator lines for UITableViewCellStyleSubtitle cells not taking the full width) in Swift

enter image description here

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("yourcell") as! UITableViewCell

    if (cell.respondsToSelector("setPreservesSuperviewLayoutMargins:")){
        cell.layoutMargins = UIEdgeInsetsZero
        cell.preservesSuperviewLayoutMargins = false
    }
}

By Checking version number :

let floatVersion = (UIDevice.currentDevice().systemVersion as NSString).floatValue

if (floatVersion > 8.0){
    cell.layoutMargins = UIEdgeInsetsZero
    cell.preservesSuperviewLayoutMargins = false
}
Related Topic