0

I have a Table View within my main UIViewController that has one non-editable prototype cell. I am trying to remove the left indent from the table view cell. No matter what method I use, the indent does not go away.

Here is what I have tried:

  • On the Table View: In Interface Builder > Attributes Inspector, I set Separator Inset to Custom with left inset of 0.

  • On the Table View Cell: In Interface Builder > Attributes Inspector, I set indentation Level and Width to 0. I also changed Separator to Custom with left 0.

I also tried the following in code:

myTable.layoutMargins = UIEdgeInsets.zero
myTable.separatorInset = UIEdgeInsets.zero

And this inside of cellForRowAt:indexPath

cell.indentationLevel = 0
cell.indentationWidth = 0
cell.layoutMargins = UIEdgeInsets.zero
return cell

Here's a screenshot of what's occurring:

Undesired left indent

I need all of the "Hello's" to left-align with the red section header text.

How can I remove the left-indent of the content?

Thanks.

Joe
  • 3,772
  • 3
  • 33
  • 64

3 Answers3

1

Have you tried using a custom cell with a label and at the required distance from the left edge?

Jackspicer
  • 1,787
  • 2
  • 13
  • 21
  • This worked great. My head was spinning trying to kill the left indent on the default table cell... All I needed to do was subclass UITableViewCell, create my custom label, and register it in cellForRow. Thanks! – Joe Dec 28 '16 at 16:17
  • Glad I could help:D – Jackspicer Jan 25 '17 at 08:04
1

I'm sure that layoutMargins is the reason of indent on UITableViewCell. But I think you can't change layoutMargins. I almost don't use textLabel of UITableViewCell. You can refer to Setting layoutMargins of UIView doesn't work.

Community
  • 1
  • 1
kai
  • 310
  • 3
  • 14
0

Try this -

helloLabel.textAlignment = .Left
cell.addSubview(helloLabel)
iDeveloper
  • 2,339
  • 2
  • 24
  • 38