Skip to content

Instantly share code, notes, and snippets.

@CVertex
Created April 14, 2010 09:17
Show Gist options
  • Save CVertex/365617 to your computer and use it in GitHub Desktop.
Save CVertex/365617 to your computer and use it in GitHub Desktop.
// somethign in here is broken
- (void)layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectInset(self.contentView.bounds, kHPadding, kVPadding);
BrandTableItem* item = self.object;
Brand* brand = item.brand;
UIImage* image = brand.imageUrl ? [[TTURLCache sharedCache] imageForURL:brand.imageUrl] : nil;
if (!image) {
image = item.defaultImage;
}
CGFloat imageContainerWidth = kThumbnailImageWidth + (kThumbnailImageSidePadding*2);
CGFloat imageContainerHeight = kThumbnailImageHeight+ (kThumbnailImageTopBottomPadding*2);
_iconView.frame = CGRectMake(4,3,kThumbnailImageWidth,kThumbnailImageHeight);
_iconView.contentMode = UIViewContentModeScaleAspectFit;
_iconView.clipsToBounds = YES;
_imageContainerView.frame = CGRectMake(kHPadding, floor(self.height/2 - imageContainerHeight/2),
imageContainerWidth, imageContainerHeight);
CGFloat maxWidth = self.contentView.width - (imageContainerWidth + kHPadding*2 + kMargin*2);
CGSize textSize = [self.textLabel.text sizeWithFont:self.textLabel.font
constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX)
lineBreakMode:self.textLabel.lineBreakMode];
CGFloat innerWidth = self.contentView.width - (kHPadding*2 + imageContainerWidth + kKeySpacing);
CGFloat innerHeight = self.contentView.height - kVPadding*2;
//
// layout name
//
CGFloat yTextLabel = (self.contentView.height - textSize.height)/2;
self.textLabel.frame = CGRectMakeWithFlooring(imageContainerWidth +(kHPadding*2)+ kKeySpacing, yTextLabel,
innerWidth, textSize.height);
// clear the background color here for some reason, UITableCell must set the bg colour automatically somewhere before or during layout
self.textLabel.backgroundColor = [UIColor clearColor];
}
// this works fine
- (void)layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectInset(self.contentView.bounds, kHPadding, kVPadding);
CategoryTableItem* item = self.object;
OfferCategory* category = item.category;
UIImage* image = category.imageUrl ? [[TTURLCache sharedCache] imageForURL:category.imageUrl] : nil;
if (!image) {
image = item.defaultImage;
}
CGFloat imageContainerWidth = kThumbnailImageWidth + (kThumbnailImageSidePadding*2);
CGFloat imageContainerHeight = kThumbnailImageHeight+ (kThumbnailImageTopBottomPadding*2);
if (![category.imageUrl isEmptyOrWhitespace]) {
_iconView.frame = CGRectMake(4,3,kThumbnailImageWidth,kThumbnailImageHeight);
_iconView.contentMode = UIViewContentModeScaleAspectFit;
_iconView.clipsToBounds = YES;
_imageContainerView.frame = CGRectMake(kHPadding, floor(self.height/2 - imageContainerHeight/2),
imageContainerWidth, imageContainerHeight);
} else {
[_imageContainerView setHidden:YES];
imageContainerWidth =0;
imageContainerHeight = 0;
}
CGFloat maxWidth = self.contentView.width - (imageContainerWidth + kHPadding*2 + kMargin*2);
CGSize textSize = [self.textLabel.text sizeWithFont:self.textLabel.font
constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX)
lineBreakMode:self.textLabel.lineBreakMode];
CGFloat innerWidth = self.contentView.width - (kHPadding*2 + imageContainerWidth + kKeySpacing);
CGFloat innerHeight = self.contentView.height - kVPadding*2;
//
// layout name
//
self.textLabel.frame = CGRectMake(imageContainerWidth +(kHPadding*2)+ kKeySpacing, kVPadding*2,
innerWidth, textSize.height);
// clear the background color here for some reason, UITableCell must set the bg colour automatically somewhere before or during layout
self.textLabel.backgroundColor = [UIColor clearColor];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment