Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
[UI] Fix height calculation of TTTableImageItems
Browse files Browse the repository at this point in the history
Factored out method to choose the font and use that for height
calculations and in setObject.
  • Loading branch information
diederich authored and jverkoey committed Feb 26, 2011
1 parent 2733e2d commit cdaa5c8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Three20UI/Sources/TTTableImageItemCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ - (void)dealloc {
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Private helpers


///////////////////////////////////////////////////////////////////////////////////////////////////
+ (UIFont*)fontForImageItem:(id)imageItem {
if ([imageItem isKindOfClass:[TTTableRightImageItem class]]) {
return TTSTYLEVAR(tableSmallFont);

} else {
return TTSTYLEVAR(tableFont);
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
Expand Down Expand Up @@ -96,7 +113,7 @@ + (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)object {

CGFloat maxWidth = tableView.width - (imageWidth + kTableCellHPadding*2 + kTableCellMargin*2);

CGSize textSize = [imageItem.text sizeWithFont:TTSTYLEVAR(tableSmallFont)
CGSize textSize = [imageItem.text sizeWithFont:[self fontForImageItem:imageItem]
constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX)
lineBreakMode:UILineBreakModeTailTruncation];

Expand Down Expand Up @@ -206,12 +223,12 @@ - (void)setObject:(id)object {
_imageView2.defaultImage = item.defaultImage;
_imageView2.urlPath = item.imageURL;

self.textLabel.font = [[self class] fontForImageItem:item];

if ([_item isKindOfClass:[TTTableRightImageItem class]]) {
self.textLabel.font = TTSTYLEVAR(tableSmallFont);
self.textLabel.textAlignment = UITextAlignmentCenter;
self.accessoryType = UITableViewCellAccessoryNone;
} else {
self.textLabel.font = TTSTYLEVAR(tableFont);
self.textLabel.textAlignment = UITextAlignmentLeft;
}
}
Expand Down

0 comments on commit cdaa5c8

Please sign in to comment.