Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - How to set View width equal to TableView Separator width

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

like image 557
Linh Avatar asked Apr 13 '26 11:04

Linh


2 Answers

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.

like image 195
Suhail kalathil Avatar answered Apr 16 '26 01:04

Suhail kalathil


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!

like image 26
vien vu Avatar answered Apr 15 '26 23:04

vien vu