[英]iOS - How to set View width equal to TableView Separator width
I am new in iOS. 我是iOS新手。 I have a
View
on top (width 1 px height) and a UITableView
below the View
. 我在顶部有一个
View
(宽度1 px高度),在View
下面有一个UITableView
。
Now, The constraint leading and trailing of the View is 10 现在,视图的约束前导和尾随是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). 我试图为TableView设置Separator Inset,其值为Left为10而Right为10但不能正常工作(视图宽度不等于TableView Separator宽度)。
I want to set the width of the View
equal to the width of the UITableView Separator
. 我想将
View
的宽度设置为等于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, 试试这个,您可以通过添加以下方法在自定义tableviewCell类中设置分隔符插入,
- (UIEdgeInsets)layoutMargins
{
return UIEdgeInsetsMake(0, 10, 0, 10);
}
Then set your view's leading and trailing constraints by 10px. 然后将视图的前导和尾随约束设置为10px。
I think it relate with margin
property. 我认为这与
margin
属性有关。 Make sure you that when you set constraint, you already uncheck this option like this 确保在设置约束时,您已经取消选中此选项
And in controller
set separatorinset
: 并在
controller
设置separatorinset
:
self.tableView.separatorInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
Hope this help! 希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.