3

I am new in iOS. I have a View on top (width 1 px height) and a UITableView below the View.

Now, The constraint leading and trailing of the View is 10
I have tried to set the Separator Inset for the TableView with value Left is 10 and Right is 10 but it not work well (the view width is not equal to TableView Separator width).

I want to set the width of the View equal to the width of the UITableView Separator.
What should I do to achieve it? Any help would be appreciated

enter image description here

Community
  • 1
  • 1
Linh
  • 57,942
  • 23
  • 262
  • 279
  • what about constraint `leading` and `trailing` of your `tableView` with `super view`? – vien vu Dec 24 '15 at 04:07
  • the constraint leading and trailing of your tableView with super view is 0 – Linh Dec 24 '15 at 04:09
  • 1
    http://stackoverflow.com/questions/25762723/remove-separatorinset-on-ios-8-uitableview-for-xcode-6-iphone-simulator refer this answer – Rohit Pradhan Dec 24 '15 at 04:25
  • Indeed. You can query the `layoutMargins` of your cell and use them to calculate the size and position of the view accordingly. – Nicolas Miari Dec 24 '15 at 04:38

2 Answers2

2

Try this , You can set the separator inset in your custom tableviewCell class by adding the below method,

- (UIEdgeInsets)layoutMargins
{
    return UIEdgeInsetsMake(0, 10, 0, 10);
}

Then set your view's leading and trailing constraints by 10px.

Suhail kalathil
  • 2,673
  • 1
  • 13
  • 12
  • 1
    Instead of changing the margins, he's better off reading them and adapting his yellow views to those values (that's what's he's asking for, after all). **Still, a pointer in the good direction.** Also, Apple recommends against changing the separator margins. – Nicolas Miari Dec 24 '15 at 04:39
1

I think it relate with margin property. Make sure you that when you set constraint, you already uncheck this option like this

enter image description here

And this: enter image description here

And in controller set separatorinset:

self.tableView.separatorInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)

Hope this help!

vien vu
  • 4,277
  • 2
  • 17
  • 30