Remove border in each table cell in swift

2019-04-20 17:25发布

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

5条回答
我命由我不由天
2楼-- · 2019-04-20 17:52

Swift 4.2

Put below code into viewDidLoad

tableView.separatorStyle = UITableViewCell.SeparatorStyle.none

查看更多
成全新的幸福
3楼-- · 2019-04-20 17:57

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()

    }
}
查看更多
Ridiculous、
4楼-- · 2019-04-20 18:00

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

查看更多
Animai°情兽
5楼-- · 2019-04-20 18:06

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
查看更多
三岁会撩人
6楼-- · 2019-04-20 18:14

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)

        }
}
查看更多
登录 后发表回答