ios - Resizing and re-positioning UILabel inside custom UICollectionViewCell -


i'm trying reposition uilabel inside custom uicollectionviewcell nib. problem iss , @ start, first item's subviews looks should (positioned code), , other items subviews positioned nib. if scroll , forth few times, loads other items ok well.

i tried , without autolayout stated in answers here , tried setting / removing constrains told here

loosing mind, great!

in feedcell did this:

-(void)layoutsubviews{         [super layoutsubviews];         [self sortviews];     } - (void) sortviews{         [_fromlable sizetofit];         [_tolable sizetofit];         [_fromyearlabel sizetofit];         [_dashlabel sizetofit];         [_dashlabel centerhorizontalinparent];          // rotate year labels         [_fromyearlabel settransform:cgaffinetransformmakerotation(m_pi / 2)];         [_tolable setx:[_dashlabel x] + [_dashlabel width] + 15 ];         [_fromyearlabel setx:[_dashlabel x] - [_fromyearlabel width] - 15 ];      } 

i tried calling [cell setneedsdisplay] in cellforitematindexpath , in willdisplaycell:foritematindexpath

my cell dequeue in cellforitematindexpath this:

// cell returned must retrieved call -dequeuereusablecellwithreuseidentifier:forindexpath: - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath {         feedcell *cell= (feedcell*)[collectionview dequeuereusablecellwithreuseidentifier:@"feedcell" forindexpath:indexpath];         nsdictionary *feed = [_datasource objectatindex:indexpath.row];         if (feed) {             [cell.mediaimage sethidden:no];             nsstring* desc = [feed objectforkey:@"desc"];             if(desc){                 cell.descriptiontextview.text = desc;                 [cell.descriptiontextview adjustfontsizetofillitscontentwithmaxfontsize:80 andminvalue:8 withfont:fmyriadproregular];                 [cell.descriptiontextview sethidden:no];             }             else             [cell.descriptiontextview sethidden:yes];              if ([feed objectforkey:@"title"]) {                 cell.titlelabel.text = [feed objectforkey:@"title"];             }             if ([feed objectforkey:@"place"]) {                 cell.placelabel.text = [feed objectforkey:@"place"];             }              if ([feed objectforkey:@"location"]) {                 [cell.locationlable sethidden:no];                 cell.locationlable.text = [feed objectforkey:@"location"];             }else{                 [cell.locationlable sethidden:yes];             }               nsdateformatter *dateformatter = [[nsdateformatter alloc] init];              // imporant - set our input date format match our input string             // if format doesn't match you'll nil string, careful             [dateformatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss"];             nsdate *datefromstring = [[nsdate alloc] init];             nsinteger yearstart = 0;             nsinteger yearend = 0;             nsinteger totalyears = 0;              if ([feed objectforkey:@"starttime"]) {                 nsstring* starttime = [feed objectforkey:@"starttime"];                 datefromstring = [dateformatter datefromstring:starttime];                 cell.fromlable.text = [datefromstring monthstringwithlength:3 capital:yes];                 yearstart = [datefromstring year];             }             if ([feed objectforkey:@"endtime"]) {                 nsstring* endtime = [feed objectforkey:@"endtime"];                 datefromstring = [dateformatter datefromstring:endtime];                 cell.tolable.text = [datefromstring monthstringwithlength:3 capital:yes];                 yearend = [datefromstring year];             }             if (yearstart == 0 && yearend == 0) {                 [cell.totalyears sethidden:yes];             }else if (yearstart > 0 && yearend == 0){                 [cell.totalyears sethidden:no];                 totalyears = [[nsdate date] year] - yearstart;             }else{                 [cell.totalyears sethidden:no];                 totalyears = yearend - yearstart;             }             cell.fromyearlabel.text = stringwithformat(@"%zd", yearstart);             cell.totalyears.text = stringwithformat(@"(%zd years)", totalyears);             [cell.mediaimage setimagewithurl:[nsurl urlwithstring:getimageurlwithidandsize([[[_datasource objectatindex:indexpath.row] objectforkey:@"media"] objectatindex:0], 1)]];          }         cell.backgroundcolor= [uicolor whitecolor];         [cell setneedsdisplay];          return cell;     } 

try following code:

(void)awakefromnib { [super awakefromnib];  self.contentview.frame = self.bounds; self.contentview.autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight; } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -