Fabio Cenni Fabio Cenni - 2 months ago 15
iOS Question

Change tableView separator insets

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?

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
}
Comments