iOS tableViewCell settings

1. Remove excess bottom line of the table

[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
复制代码

2. Set the dividing line head in a custom display self Representative cell tableViewCell

if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
    [self setSeparatorInset:UIEdgeInsetsZero];
}
    
if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
    [self setLayoutMargins:UIEdgeInsetsZero];
}
    
if([self respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
    [self setPreservesSuperviewLayoutMargins:NO];
}
复制代码

3. code layout tableview cell gap change the layout frame rewriting method of UITableViewCell

- (void)setFrame:(CGRect)frame{
    frame.origin.x += 5;
    frame.origin.y += 5;
    frame.size.height -= 5;
    frame.size.width -= 10;
    [super setFrame:frame];
}
复制代码

4. Dynamic height calculation tableviewCell

//    获取最底部view 的bottom值
//    NSArray *views = [self.contentView.subviews sortedArrayUsingComparator:^NSComparisonResult(UIView *view1, UIView *view2) {
//        NSString *top1 = [NSString stringWithFormat:@"%f", view1.frame.origin.y];
//        NSString *top2 = [NSString stringWithFormat:@"%f", view2.frame.origin.y];
//        NSComparisonResult result = [top1 compare:top2 options:NSNumericSearch];
//        NSLog(@"^^^::%ld", (long)result);
//
//        return result == NSOrderedDescending;
//    }];
NSArray *views = self.contentView.subviews;
UIView * bottomView = views.firstObject;
CGFloat height = bottomView.frame.origin.y+bottomView.frame.size.height;
_model.cellHeight = height + 10;
复制代码

PS: My blog address

Guess you like

Origin blog.csdn.net/weixin_33989780/article/details/91397772