博客> TableView(表视图)
TableView(表视图)
2018-05-23 02:29 评论:0 阅读:749 沐晨_梦雪
ios tableview

TableView(表视图)

cell: 1.设置单元格选中的字体颜色和背景色 cell.cellLabel.highlightedTextColor = LGColor(255, 96, 36, 1.0); cell.selectedBackgroundView = [[UIView alloc]initWithFrame:cell.frame]; cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];

2.cell自适应高度

  • (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath {

    NSString* text = self.arr[indexPath.row];

    CGSize constraint = CGSizeMake(375-40, 100);

    NSAttributedString* attributedText = [[NSAttributedString alloc]initWithString:text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];

    CGRect rect = [attributedText boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin context:nil];

    CGSize size = rect.size;

    CGFloat height = MAX(size.height, 20); NSLog(@"%f",height); return height+10; } 3.除去空的cell tableView.tableFooterView = [[UIView alloc]init];

4.除去cell的分割线 tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

5.解决分割线不全的问题 -(void)viewDidLayoutSubviews { if ([recordTableView respondsToSelector:@selector(setSeparatorInset:)]) { [recordTableView setSeparatorInset:UIEdgeInsetsZero]; } if ([recordTableView respondsToSelector:@selector(setLayoutMargins:)]) { [recordTableView setLayoutMargins:UIEdgeInsetsZero]; } } -(void)tableView:(UITableView )tableView willDisplayCell:(UITableViewCell )cell forRowAtIndexPath:(NSIndexPath *)indexPath{

if (tableView == recordTableView) {

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

}

}

收藏
2
sina weixin mail 回到顶部