Skip to content

Instantly share code, notes, and snippets.

@adamjernst
Last active November 28, 2017 01:35
Show Gist options
  • Save adamjernst/c7bd7e5f98de5dc82e3a to your computer and use it in GitHub Desktop.
Save adamjernst/c7bd7e5f98de5dc82e3a to your computer and use it in GitHub Desktop.
@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