Remove border in each table cell in swift

夙愿已清 提交于 2020-01-23 04:42:24

问题


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 .


回答1:


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



回答2:


select tableview in storyboard and select seperator style to None




回答3:


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

    }
}



回答4:


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)

        }
}



回答5:


Swift 4.2

Put below code into viewDidLoad

tableView.separatorStyle = UITableViewCell.SeparatorStyle.none



来源:https://stackoverflow.com/questions/37108647/remove-border-in-each-table-cell-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!