为什么即使我将约束设置为0,UITableView上仍有余量

dra*_*sea 0 uitableview ios swift

我刚刚买了一本书并在Swift中学习编程IOS.我想创建一个像Snapchat这样的表视图列表: 在此输入图像描述

然后我将UITableView的所有约束设置为 在此输入图像描述0:

但是,桌子左边还有一个余量,为什么呢?

在此输入图像描述

Ash*_*kad 5

单击后在界面构建器中搜索分隔符插入 UITableView

之前

并将其更改为自定义.现在您可以将Left Inset设置为0

后

Objective-C的

viewDidLoad

[tableView setSeparatorInset:UIEdgeInsetsZero];
Run Code Online (Sandbox Code Playgroud)

添加以下代码 cellForRowAtIndexPath:

if ([cell respondsToSelector:@selector(preservesSuperviewLayoutMargins)]){
    cell.layoutMargins = UIEdgeInsetsZero;
    cell.preservesSuperviewLayoutMargins = false;
}
Run Code Online (Sandbox Code Playgroud)

迅速

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
    [[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}
Run Code Online (Sandbox Code Playgroud)