Skip to content

Instantly share code, notes, and snippets.

@mwhuss
Created March 5, 2014 20:37
Show Gist options
  • Select an option

  • Save mwhuss/9376071 to your computer and use it in GitHub Desktop.

Select an option

Save mwhuss/9376071 to your computer and use it in GitHub Desktop.
@interface SNDayView ()
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation SNDayView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor redColor];
[self addSubview:self.titleLabel];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
if (CGRectGetWidth(self.bounds) < 300) {
self.titleLabel.frame = CGRectZero;
}
else {
self.titleLabel.frame = CGRectZero;
}
}
- (CGSize)sizeThatFits:(CGSize)size {
CGFloat width = 100;
if ([self.titleLabel.text length] > 200) {
width = 200;
}
return CGSizeMake(CGRectGetWidth(width, 100));
}
#pragma mark - private properties
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = [UIColor blueColor];
}
return _titleLabel;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment