2010年10月15日金曜日

UITableViewCellのコンテンツをすべて表示できるようにheightの自動調整

#define kCELL_LABEL_FONT [UIFont fontWithName:@"Helvetica-Bold" size:18.0f]
#define kCELL_DESLABEL_FONT [UIFont fontWithName:@"Helvetica" size:12.0f]


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{

NSUInteger row = [indexPath row];

float accesoryWidth = (render.mp_isAccessoryView == NO) ? 0.0f : 30.0f;
CGSize constraintSize = CGSizeZero;
if ([render getSrcImage])
{
constraintSize = CGSizeMake(tableView.frame.size.width - 2.0 * kCELL_DefaultInterval - kCELL_Image_size.width - accesoryWidth,CGFLOAT_MAX);
}
else
{
constraintSize = CGSizeMake(tableView.frame.size.width - 2.0 * kCELL_DefaultInterval - accesoryWidth,CGFLOAT_MAX);
}

CGSize labelSize = [[render getDisplay] sizeWithFont: kCELL_LABEL_FONT constrainedToSize:constraintSize lineBreakMode:UILineBreakModeCharacterWrap];
CGSize detailSize = [[render getDes] sizeWithFont: kCELL_DESLABEL_FONT constrainedToSize:constraintSize lineBreakMode:UILineBreakModeCharacterWrap];

CGFloat result = MAX(44.0, labelSize.height + detailSize.height + 12);

return result;
}

0 件のコメント:

コメントを投稿