Skip to content

Instantly share code, notes, and snippets.

@hatfinch
Created July 26, 2011 17:40
Show Gist options
  • Save hatfinch/1107320 to your computer and use it in GitHub Desktop.
Save hatfinch/1107320 to your computer and use it in GitHub Desktop.
Autogenerated ivars not retained by ARC
@interface OLVIconViewCell : UIView
@property(nonatomic, readonly) NSString *reuseIdentifier;
@property(nonatomic, readonly) UILabel *textLabel;
@property(nonatomic, readonly) UILabel *detailTextLabel;
@property(nonatomic, readonly) UIImageView *imageView;
- (id)initWithReuseIdentifier:(NSString *)identifier;
- (void)prepareForReuse;
@end
#import "OLVIconViewCell.h"
@interface OLVIconViewCell ()
{
// UILabel *myTextLabel;
// UILabel *myDetailTextLabel;
// UIImageView *myImageView;
// NSString *myReuseIdentifier;
CGSize mySize;
}
@end
@implementation OLVIconViewCell
@synthesize reuseIdentifier = myReuseIdentifier;
@synthesize textLabel = myTextLabel, detailTextLabel = myDetailTextLabel, imageView = myImageView;
- (UILabel *)cellLabel
{
UILabel *label = [[UILabel alloc] init];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.textAlignment = UITextAlignmentCenter;
return label;
}
- (id)initWithReuseIdentifier:(NSString *)identifier
{
self = [super initWithFrame:CGRectZero];
if (self)
{
myReuseIdentifier = identifier;
myTextLabel = [self cellLabel];
myTextLabel.textColor = [UIColor whiteColor];
myDetailTextLabel = [self cellLabel];
myDetailTextLabel.textColor = [UIColor lightGrayColor];
myImageView = [[UIImageView alloc] init];
}
return self;
}
- (void)prepareForReuse
{
}
- (void)performLayout
{
CGSize size = self.bounds.size;
CGSize textSize = [myTextLabel sizeThatFits:size];
CGSize detailTextSize = [myDetailTextLabel sizeThatFits:size];
myDetailTextLabel.Frame = CGRectMake(0.0, size.height - detailTextSize.height, size.width, detailTextSize.height);
myTextLabel.frame = CGRectMake(0.0, size.height - detailTextSize.height - textSize.height, size.width, textSize.height);
myImageView.frame = CGRectMake(0.0, 0.0, size.width, size.height - textSize.height - detailTextSize.height);
}
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
if (!CGSizeEqualToSize(frame.size, mySize))
{
mySize = frame.size;
[self performLayout];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment