UItableView cell 自适应高度

来源:互联网 发布:mac系统破解版下载 编辑:程序博客网 时间:2024/04/29 21:23
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];if (cell == nil) {    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;        cell.textLabel.numberOfLines = 0;        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{NSString *cellText = @"Go get some text for your cell.";UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];return labelSize.height + 20;}---------------------------other mehod the solve this problem
UILabel* label = [[UILabel alloc] initWithFrame:cell.frame];label.numberOfLines = <...an appriate number of lines...>label.text = <...your text...>[label sizeToFit];[cell addSubview:label];[label release];
原创粉丝点击