简体   繁体   中英

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

在此输入图像描述

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.

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

在此输入图像描述

And this: 在此输入图像描述

And in controller set separatorinset :

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

Hope this help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM