如何将UIImage设置为UITableView单元格,该单元格根据我在UILabel中输入的文本动态计算单元格高度?
我正在创建UITableView,其中每个单元格大小将根据我输入的文本计算。 我正在计算heighForRowAtIndexPath中的单元格大小如何将UIImage设置为UITableView单元格,该单元格根据我在UILabel中输入的文本动态计算单元格高度?,uitableview,uiimageview,uilabel,cgrect,Uitableview,Uiimageview,Uilabel,Cgrect,我正在创建UITableView,其中每个单元格大小将根据我输入的文本计算。 我正在计算heighForRowAtIndexPath中的单元格大小 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { NSString *text = [tableData objectAtIndex:[indexPath row]]; CGSize co
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [tableData objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(210.0f, 20000.0f);
size = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
height = MAX(size.height, 44.0f);
return height + (CCM * 2);
}
NSString *text = [tableData objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(210.0f, 20000.0f);
CGSize size1 = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height1 = MAX(size1.height, 44.0f);
[cell.cellBackgroundBottom setFrame:CGRectMake(75.0f, 18.0f, 228.0f, height1 + 10.0f)];
这就是我如何计算每个单元格的高度,现在我的问题是-我想在每个单元格中添加图像,比如注释框?这样地
你可以看到这些评论框
我所做的是把我的形象分成两部分
第一个有一个顶部的部分,这是工作良好的每一个细胞开始图像即将到来
现在,在修复底部部件时,我面临问题
对于单元格中的小文本,UILable工作正常
当UILabel中的文本大小增加时,它并没有得到适当的调整
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"cell";
NSLog(@"index path %d", indexPath.row);
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[[MyTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell.cellBackgroundBottom setFrame:CGRectMake(75.0f, 92.0f, 228.0f, height + 25.0f)];
[cell.cellContent setText:(NSString*)[tableData objectAtIndex:[indexPath row]]];
[cell.cellContent sizeToFit];
CGRect theFrame = [cell.cellContent frame];
theFrame.size.width = 210.0f;
[cell.cellContent setFrame: theFrame];
return cell;
}
我创建了一个名为MYTableCell的UITableView子类,在该子类中,我定义了每个单元格中所需的内容
// Creating UILabel for cell content or comments block
cellContent = [[UILabel alloc]initWithFrame: CGRectMake( 90.0f, 15.0f, 210.0f, 60.0f)] ;
[cellContent setLineBreakMode:UILineBreakModeWordWrap];
cellContent.numberOfLines = 0;
[cellContent setMinimumFontSize:15.0f];
[cellContent setBackgroundColor:[UIColor clearColor]];
// [cellContent setTextColor:[UIColor colorWithRed:73.0f green:73.0f blue:73.0f alpha:1.0f]];
[cellContent setFont:[UIFont fontWithName:@"Helvetica" size:12.0f]];
cellContent.textAlignment = UITextAlignmentLeft;
[cellContent setTag:1];
[self addSubview:cellContent];
[cellContent release];
cellBackgroundTop = [[UIImageView alloc] initWithFrame:CGRectMake(60.0f, 5.0f, 243.0f, 13.5f)];
[cellBackgroundTop setImage:[UIImage imageNamed:@"comments.png"]];
[self addSubview:cellBackgroundTop];
[cellBackgroundTop release];
cellBackgroundBottom = [[UIImageView alloc] initWithFrame:CGRectZero];
[cellBackgroundBottom setImage:[UIImage imageNamed:@"Untitled-1_09.png"]];
[self addSubview:cellBackgroundBottom];
[cellBackgroundBottom release];
我的问题得到了答案 . 这是我在牢房里必须做的事情
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [tableData objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(210.0f, 20000.0f);
size = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
height = MAX(size.height, 44.0f);
return height + (CCM * 2);
}
NSString *text = [tableData objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(210.0f, 20000.0f);
CGSize size1 = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height1 = MAX(size1.height, 44.0f);
[cell.cellBackgroundBottom setFrame:CGRectMake(75.0f, 18.0f, 228.0f, height1 + 10.0f)];