UITableViewCell 下边的分割线默认是到不了最左边的,但是有时候我们需要让它顶到头,需要设置tableView和cell的边界设置,距离边界为0;
首先设置tableView:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在代理cell要显示的代理方法中设置cell
////cell将要显示时调用
- (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];
}
}
此时,cell下划线就会一直顶到最左边。
在iOS开发中,当遇到UITableViewCell的下边分割线无法顶到最左边时,可以通过设置tableView和cell的边距属性来实现。具体做法包括设置tableView的separatorInset和layoutMargins为零,以及在cell将要显示时,同样设置cell的separatorInset和layoutMargins为零,以此确保下划线能够顶到最左边。

被折叠的 条评论
为什么被折叠?



