Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove border in each table cell in swift

I would like to remove border bottom line of each Question table rows. Another thing is that I would like to remove the left padding space in each row. How to implement it in swift iOS 9.0 .

enter image description here

like image 241
May Phyu Avatar asked May 09 '16 05:05

May Phyu


4 Answers

I use the method below

class viewController: UIViewController {

@IBOutlet var tableView: UITableView!

    override func viewDidLoad() {
            super.viewDidLoad()

            self.tableView.separatorInset = UIEdgeInsetsMake(0, UIScreen.main.bounds.width, 0, 0)

        }
}
like image 141
Jeri P.M Avatar answered Nov 02 '22 11:11

Jeri P.M


You can remove bottom border by writing this below line in viewdidLoad,

self.tblMyTable.separatorStyle = UITableViewCellSeparatorStyle.None

And Remove left padding by writing this in cellForRow,

cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero 

Update for Swift 3.0:

cell?.separatorInset = UIEdgeInsets.zero
cell?.layoutMargins = UIEdgeInsets.zero
like image 25
Jigar Tarsariya Avatar answered Nov 02 '22 12:11

Jigar Tarsariya


select tableview in storyboard and select seperator style to Noneenter image description here

like image 12
Jack.Right Avatar answered Nov 02 '22 11:11

Jack.Right


Another simple solution that worked for me for removing bottom lines (separators) just for empty rows - tested on Swift 4, Xcode 9 & iOS 11:

class viewController: UIViewController {

    @IBOutlet var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView?.tableFooterView = UIView()

    }
}
like image 3
deevee Avatar answered Nov 02 '22 11:11

deevee