Instantly share code, notes, and snippets.

Embed
What would you like to do?
@implementation FBStoryView
{
FBHeaderView *_headerView;
FBMessageView *_messageView;
FBAttachmentView *_attachmentView;
FBLikeBarView *_likeBarView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
_headerView = [[FBHeaderView alloc] init];
_messageView = [[FBMessageView alloc] init];
_attachmentView = [[FBAttachmentView alloc] init];
_likeBarView = [[FBLikeBarView alloc] init];
[self addSubview:_headerView];
[self addSubview:_messageView];
[self addSubview:_attachmentView];
[self addSubview:_likeBarView];
}
return self;
}
- (CGSize)sizeThatFits:(CGSize)size
{
return CGSizeMake(size.width,
[_headerView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height
+ [_messageView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height
+ [_attachmentView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height
+ [_likeBarView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height);
}
- (void)layoutSubviews
{
CGFloat width = [self bounds].size.width;
CGFloat y = 0;
CGFloat headerHeight = [_headerView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height;
[_headerView setFrame:CGRectMake(0, y, width, headerHeight)];
y += headerHeight;
CGFloat messageHeight = [_messageView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height;
[_messageView setFrame:CGRectMake(0, y, width, messageHeight)];
y += messageHeight;
CGFloat attachmentHeight = [_attachmentView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height;
[_attachmentView setFrame:CGRectMake(0, y, width, attachmentHeight)];
y += attachmentHeight;
CGFloat likeBarHeight = [_likeBarView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height;
[_likeBarView setFrame:CGRectMake(0, y, width, likeBarHeight)];
y += likeBarHeight;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment