[...]
// Push the value into
// Build the UI...
#pragma mark -
#pragma mark UIView
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)layoutSubviews {
[super layoutSubviews];
TTTableImageItem* item = self.object;
UIImage* image = item.imageURL ? [[TTURLCache sharedCache] imageForURL:item.imageURL] : nil;
if (!image) {
image = item.defaultImage;
}
if ([_item isKindOfClass:[TTTableRightImageItem class]]) {
CGFloat imageWidth = image
? image.size.width
: (item.imageURL ? kDefaultImageSize : 0);
CGFloat imageHeight = image
? image.size.height
: (item.imageURL ? kDefaultImageSize : 0);
if (_imageView2.urlPath || image) {
CGFloat innerWidth = self.contentView.width - (kTableCellHPadding*2
+ imageWidth + kKeySpacing);
CGFloat innerHeight = self.contentView.height - kTableCellVPadding*2;
self.textLabel.frame = CGRectMake(kTableCellHPadding, kTableCellVPadding,
innerWidth, innerHeight);
_imageView2.frame = CGRectMake(self.textLabel.right + kKeySpacing,
floor(self.height/2 - imageHeight/2),
imageWidth, imageHeight);
} else {
self.textLabel.frame = CGRectInset(self.contentView.bounds,
kTableCellHPadding, kTableCellVPadding);
_imageView2.frame = CGRectZero;
}
} else {
if (_imageView2.urlPath || image) {
CGFloat iconWidth = image
? image.size.width
: (item.imageURL ? kDefaultImageSize : 0);
CGFloat iconHeight = image
? image.size.height
: (item.imageURL ? kDefaultImageSize : 0);
TTImageStyle* style = [item.imageStyle firstStyleOfClass:[TTImageStyle class]];
if (style) {
_imageView2.contentMode = style.contentMode;
_imageView2.clipsToBounds = YES;
_imageView2.backgroundColor = [UIColor clearColor];
if (style.size.width) {
iconWidth = style.size.width;
}
if (style.size.height) {
iconHeight = style.size.height;
}
}
_imageView2.frame = CGRectMake(kTableCellHPadding, floor(self.height/2 - iconHeight/2),
iconWidth, iconHeight);
CGFloat innerWidth = self.contentView.width - (kTableCellHPadding*2
+ iconWidth + kKeySpacing);
CGFloat innerHeight = self.contentView.height - kTableCellVPadding*2;
self.textLabel.frame = CGRectMake(kTableCellHPadding + iconWidth + kKeySpacing,
kTableCellVPadding,
innerWidth, innerHeight);
} else {
self.textLabel.frame = CGRectInset(self.contentView.bounds,
kTableCellHPadding, kTableCellVPadding);
_imageView2.frame = CGRectZero;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)didMoveToSuperview {
[super didMoveToSuperview];
if (self.superview) {
_imageView2.backgroundColor = self.backgroundColor;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTTableViewCell
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)setObject:(id)object {
if (_item != object) {
[super setObject:object];
TTTableImageItem* item = object;
_imageView2.style = item.imageStyle;
_imageView2.defaultImage = item.defaultImage;
_imageView2.urlPath = item.imageURL;
self.textLabel.font = [[self class] fontForImageItem:item];
if ([_item isKindOfClass:[TTTableRightImageItem class]]) {
self.textLabel.textAlignment = UITextAlignmentCenter;
self.accessoryType = UITableViewCellAccessoryNone;
} else {
self.textLabel.textAlignment = UITextAlignmentLeft;
}
}
}