美文网首页
iOS 小知识点(UITableView)

iOS 小知识点(UITableView)

作者: 王红笑 | 来源:发表于2017-12-08 11:07 被阅读0次

去掉cell分割线前的15个像素

(1)、首先在viewDidLoad中添加以下方法
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
(2)、然后重写willDisplayCell方法
-(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];
    }
}

tableViewcell点击,取消点击效果

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

tableViewCell 去掉分割线

    tableView.separatorStyle = UITableViewCellSelectionStyleNone;

iOS 11 设置footer和header高度,需要

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

相关文章

网友评论

      本文标题:iOS 小知识点(UITableView)

      本文链接:https://www.haomeiwen.com/subject/esfeixtx.html