Remove border in each table cell in swift

16,272

Solution 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

Solution 2

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

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

    }
}

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

        }
}
Share:
16,272
May Phyu
Author by

May Phyu

Updated on June 14, 2022

Comments

  • May Phyu
    May Phyu about 2 years

    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

  • May Phyu
    May Phyu about 8 years
    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.
  • Jigar Tarsariya
    Jigar Tarsariya about 8 years
    It would be better if you display question and answer both in single cell by using Custom cell. Is it possible for you?
  • May Phyu
    May Phyu about 8 years
    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.
  • Jigar Tarsariya
    Jigar Tarsariya about 8 years
    You have to give question and answer both in custom cell (two different label or else). I think it will be easy for you.
  • Adrien G
    Adrien G over 6 years
    god I was looking for an "imaginary" bottom extra space... thanks a lot
  • sɐunıɔןɐqɐp
    sɐunıɔןɐqɐp almost 6 years
    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?. Thanks