ios - UICollectionViewCell AutoLayout dynamic height based on UILabel -


i using auto layout , size classes uicollectionviewcell. idea make ui similar instagram.

the problem can't understand how add proper autolayout because seems add missing constraint didn't things magically.

enter image description here

when add constraints, there no warning, shows "will attempt recover breaking constraint" on target output. goal make profile cell dynamic based on iphone types, , dynamic height based on biolabel. make static wrong, because when use method

systemlayoutsizefittingsize:uilayoutfittingcompressedsize 

it return zero, , guess because of misplace autolayout constraints. can advice me how can calculate cell's size based on it's constraints? had created project in github, anyhelp appreciated!

collectionviewautolayout

i downloaded code , found issue. see, can solve issue replacing line of codes in collectionview:layout:sizeforitematindexpath method.

- (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath {     if (indexpath.section == 0) {         cgfloat height = [self findheightfortext:@"description yourself, , impact did environment. did environment. description yourself, , impact did environment. did environment. , impact did environment. did environment. , impact did environment. did environment." havingmaximumwidth:[uiscreen mainscreen].bounds.size.width andfont:[uifont systemfontofsize:[uifont systemfontsize]]];         return cgsizemake([uiscreen mainscreen].bounds.size.width, 150 + height);     }     else {         return cgsizemake((([uiscreen mainscreen].bounds.size.width - 2.0) / 3.0), (([uiscreen mainscreen].bounds.size.width - 4.0) / 3.0));     } } 

add method calculate height dynamically.

 #pragma mark - height calculation method - (cgfloat)findheightfortext:(nsstring *)text havingmaximumwidth:(cgfloat)widthvalue andfont:(uifont *)font {     cgsize size = cgsizezero;     if (text) {         //ios 7         cgrect frame = [text boundingrectwithsize:cgsizemake(widthvalue, cgfloat_max) options:nsstringdrawinguseslinefragmentorigin | nsstringdrawingusesfontleading attributes:@{ nsfontattributename:font } context:nil];         size = cgsizemake(frame.size.width, frame.size.height + 1);     }     return size.height; } 

replace once , test in devices , let me know... hope helps :)


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -