Remove border in each table cell in swift
Asked Answered
U

4

13

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

Unmitigated answered 9/5, 2016 at 5:59 Comment(1)
I think You should use Custom Cell Having two labels for Question & Answer..!!!Intitule
C
24

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
Carafe answered 9/5, 2016 at 6:8 Comment(4)
Your code is remove border totally. I just want to remove the border bottom line of "Question" rows. So, if I remove this "Question" and "Answer" looks like in one row/one group. I want like this.Unmitigated
It would be better if you display question and answer both in single cell by using Custom cell. Is it possible for you?Carafe
It would be great. How could I make it? I'm new for iOS . I'm just learning by viewing tutorials. Currently, I got the data from Rest. .Please help me.Unmitigated
You have to give question and answer both in custom cell (two different label or else). I think it will be easy for you.Carafe
P
12

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

Protoactinium answered 9/5, 2016 at 6:13 Comment(1)
god I was looking for an "imaginary" bottom extra space... thanks a lotTextile
N
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()

    }
}
Nailhead answered 24/9, 2018 at 9:34 Comment(0)
P
1

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)

        }
}
Poppyhead answered 6/7, 2018 at 6:26 Comment(1)
Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. ThanksMerrie

© 2022 - 2024 — McMap. All rights reserved.