iOS -- UITableViewCell 下边的分割线左边顶不到头的问题

    xiaoxiao2022-06-29  60

    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下划线就会一直顶到最左边。

    转载请注明原文地址: https://ju.6miu.com/read-1125093.html

    最新回复(0)