Created
March 6, 2016 10:07
-
-
Save xta0/cc8764619f90866adeb2 to your computer and use it in GitHub Desktop.
flexlayout-imperative-code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (CGSize)sizeThatFits:(CGSize)size | |
| { | |
| return CGSizeMake(size.width, | |
| [_name sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height | |
| + [_content sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height | |
| + 30 );//padding | |
| } | |
| - (void)layoutSubviews{ | |
| [super layoutSubviews]; | |
| float w = CGRectGetWidth(self.bounds); | |
| float y = 10; | |
| float iconWidth = 40; | |
| float starWidth = 70; | |
| float padding = 10; | |
| float spacing = 5; | |
| float timeWidth = [_time sizeThatFits:CGSizeMake(w, CGFLOAT_MAX)].width; | |
| float nameContainerWidth = w - iconWidth - 2*padding - starWidth - timeWidth; | |
| float nameStringWidth = [_name sizeThatFits:CGSizeMake(nameContainerWidth, 14)].width; | |
| float nameWidth = MIN(nameStringWidth, nameContainerWidth); | |
| float contentWidth = [_content sizeThatFits:CGSizeMake(w-iconWidth - 2*padding, CGFLOAT_MAX)].width; | |
| float contentHeight = [_content sizeThatFits:CGSizeMake(w-iconWidth - 2*padding, CGFLOAT_MAX)].height; | |
| _icon.frame = CGRectMake(padding, y, iconWidth, iconWidth); | |
| _name.frame = CGRectMake(padding*2 + iconWidth, y, nameWidth, 14); | |
| _starView.frame = CGRectMake(padding*2 + iconWidth+nameWidth+spacing, y, starWidth, 14); | |
| _time.frame = CGRectMake(w-padding-timeWidth, y, timeWidth, 14); | |
| _content.frame = CGRectMake(padding*2 + iconWidth, padding*2 + 14, contentWidth, contentHeight); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment