我有一个UITableView
,其中的分隔符没有全宽。它在左侧前10个像素结束。我在viewDidLoad()
中使用了这段代码。
self.tableView.layoutMargins = UIEdgeInsetsZero;
也可以在故事板中选择自定义选择器或默认选择器。现在,所有填充的单元格都没有全宽选择器,但空的单元格具有全宽。
我该如何解决这个问题呢?
发布于 2014-10-23 08:20:15
我从这篇文章中得到了答案:iOS 8 UITableView separator inset 0 not working
只需在您的UITableViewController
上添加以下代码
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
发布于 2016-02-13 00:45:11
在你的UITableViewCell
中
转到界面生成器中的Attributes Inspector,简单地将"15“更改为0。对您希望更改的所有单元格执行此操作。
您可能需要在tableViewCell
中添加[cell setLayoutMargins:UIEdgeInsetsZero];
发布于 2016-12-13 22:01:24
对于Swift 3:
override func viewDidLoad() {
super.viewDidLoad()
tableView.separatorInset = .zero
tableView.layoutMargins = .zero
}
https://stackoverflow.com/questions/26519248
复制相似问题