ios - UICollectionViewCell height increase incorrectly on iPhone 6 -
i using uicollectionview , using custom uicollectionviewcell. user created posts showed on news feed screen. based on length of text, increasing height of cell. there strange spacing appears under "say something" text field.
when user enters text pressing enter, it's works well. if user enters number of lines without pressing enter issue occurs.
this code works on iphone 5 not on iphone 6 , 6 plus. stuck on issue since last 1 week. issue related iphone 6 , 6 plus only?
i didn't find relevant question problem that's why asking new question.
- (void)configurecell:(newsfeedobj *)newsfeed{ self.layer.borderwidth = 1; self.layer.bordercolor = [uicolor colorwithred:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1].cgcolor; self.btnpostcomment.enabled = no; self.btnpostcomment.titlelabel.textcolor = [uicolor colorwithred:191.0/255.0 green:191.0/255.0 blue:191.0/255.0 alpha:1.0]; self.postid = newsfeed.postid; float yposition = 0; //*********************post username , tagged users setting********* self.username.enabledtextcheckingtypes = nstextcheckingtypelink; // automatically detect links when label text subsequently changed self.username.shadowcolor = [uicolor whitecolor]; self.username.delegate = self; // delegate methods called when user taps on link (see `tttattributedlabeldelegate` protocol) self.username.numberoflines = 4; self.username.linespacing = 5; [self settingusersectiondetailwithnewsfeed:newsfeed]; cgrect frame = self.username.frame; frame.size.height = [self.username sizethatfits:self.username.frame.size].height+3; self.username.frame = frame; //set time , locatin postion accordint name lable. [self.timelocationview setframe:cgrectmake(self.timelocationview.frame.origin.x, (self.username.frame.origin.y+self.username.frame.size.height)+3, self.timelocationview.frame.size.width, self.timelocationview.frame.size.height)]; [self.usersection setframe:cgrectmake(self.usersection.frame.origin.x, self.usersection.frame.origin.y, self.usersection.frame.size.width, self.timelocationview.frame.origin.y+self.timelocationview.frame.size.height+5)]; //****************************************user location setting if (newsfeed.postlocation.length>0) { self.location.hidden = no; self.locationiconimg.hidden = no; self.location.text = newsfeed.postlocation; }else{ self.location.hidden = yes; self.locationiconimg.hidden = yes; } //**********************check post spam/offensive/or post yourself******************** if (newsfeed.postuser.user_id == [connectionmanager getinstance].userprofile.user_id) { [self.btnflag setimage:[uiimage imagenamed:@"edit-report"] forstate:uicontrolstatenormal]; }else{ if (newsfeed.postreportfromcurrentuser) { if ([newsfeed.postreportfromcurrentuser[@"kind"] isequaltostring:@"offensive"] || [newsfeed.postreportfromcurrentuser[@"kind"] isequaltostring:@"spam"]) { [self.btnflag setimage:[uiimage imagenamed:@"report_active"] forstate:uicontrolstatenormal]; }else{ [self.btnflag setimage:[uiimage imagenamed:@"report_inactive"] forstate:uicontrolstatenormal]; } } } //post time setting self.dateadded.text = [self timeleftsincedate:[self getdatefromstring: newsfeed.postcreatedat]]; //post edit long gesture uilongpressgesturerecognizer *posttextedit = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(texteditpost:)]; [self.description addgesturerecognizer:posttextedit]; //***********************************post user profile image setting nsdictionary *postuserimgdict = newsfeed.postuser.avatar[@"medium"]; nsstring *userimgurl = @""; if (![postuserimgdict[@"url"] ismemberofclass:[nsnull class]]) { userimgurl = postuserimgdict[@"url"]; } [self.profileimage sd_setimagewithurl:[nsurl urlwithstring:userimgurl] placeholderimage:[uiimage imagenamed:@"avatar"]]; [self.profileimage setupimageviewer]; //*************************************post text setting here self.description.text = newsfeed.postbody; cgsize rect; if (![newsfeed.postbody isequaltostring:@""]) { /*nsdictionary *attributes = @{nsfontattributename:[uifont fontwithname:@"arial" size:14.0f]}; nsattributedstring *descstring = [[nsattributedstring alloc] initwithstring:self.description.text attributes:attributes]; self.description.attributedtext = descstring;*/ [self.description setattributes: [nsdictionary dictionarywithobject:[uifont fontwithname:@"arial" size:14.0f] forkey:nsfontattributename]]; rect =[self.description suggestedframesizetofitentirestringconstrainedtowidth:self.usersection.frame.size.width-20]; //rect = [self.description sizethatfits:cgsizemake(self.usersection.frame.size.width-20, cgfloat_max)]; /*if (self.usersection.height>60) { [description setframe:cgrectmake(self.usersection.frame.origin.x+10, self.usersection.frame.origin.y+self.usersection.frame.size.height+10, self.usersection.frame.size.width-20, rect.height+10)]; }else{ [description setframe:cgrectmake(self.usersection.frame.origin.x+10, self.usersection.frame.origin.y+self.usersection.frame.size.height+10, self.usersection.frame.size.width-20, rect.height+10)]; }*/ [description setframe:cgrectmake(self.usersection.frame.origin.x+10, self.usersection.frame.origin.y+self.usersection.frame.size.height+10, self.usersection.frame.size.width-20, rect.height+10)]; if(is_iphone_5) { yposition = self.description.frame.origin.y+self.description.frame.size.height; } else { yposition = self.description.frame.origin.y + (rect.height + 10); } }else{ yposition = self.usersection.frame.origin.y+self.usersection.frame.size.height+10; } //************************************************************************* //post image setting here if(![newsfeed.postimageurl ismemberofclass:[nsnull class]] && ![newsfeed.postimageurl isequaltostring:@""]){ [self.postedimage sd_setimagewithurl:[nsurl urlwithstring:newsfeed.postimageurl] placeholderimage:nil]; self.postedimage.hidden = no; self.postedimage.frame = cgrectmake(0, yposition, self.postedimage.frame.size.width, self.postedimage.frame.size.height); yposition = self.postedimage.frame.origin.y+self.postedimage.frame.size.height; }else{ self.postedimage.hidden = yes; } //***************************rating section ************************************ self.ratingsection.frame = cgrectmake(self.ratingsection.frame.origin.x, yposition, self.ratingsection.frame.size.width, self.ratingsection.frame.size.height); yposition = self.ratingsection.frame.origin.y+self.ratingsection.frame.size.height; //***************************ratingcount section ************************************ self.countsection.frame = cgrectmake(self.countsection.frame.origin.x, yposition, self.countsection.frame.size.width, self.countsection.frame.size.height); if (newsfeed.postratingaction.count>0) { self.lblawesome.text = [nsstring stringwithformat:@"%ld .",(long)[newsfeed.postratingaction[0] integervalue]]; self.lblwhatevs.text = [nsstring stringwithformat:@"%ld .",(long)[newsfeed.postratingaction[1] integervalue]]; self.lblnobueno.text = [nsstring stringwithformat:@"%ld .",(long)[newsfeed.postratingaction[2] integervalue]]; if (newsfeed.postreactionfromcurrentuser.count>0) { if ([newsfeed.postreactionfromcurrentuser[@"kind"] isequaltostring:@"awesome"]) { self.btnawesome.selected = yes; self.btnwhatevs.selected = no; self.btnnobueno.selected = no; }else if ([newsfeed.postreactionfromcurrentuser[@"kind"] isequaltostring:@"whatevs"]) { self.btnawesome.selected = no; self.btnwhatevs.selected = yes; self.btnnobueno.selected = no; }else if ([newsfeed.postreactionfromcurrentuser[@"kind"] isequaltostring:@"nobueno"]){ self.btnawesome.selected = no; self.btnwhatevs.selected = no; self.btnnobueno.selected = yes; } }else{ self.btnawesome.selected = no; self.btnwhatevs.selected = no; self.btnnobueno.selected = no; } } yposition = self.countsection.frame.origin.y+self.countsection.frame.size.height; //***************************comment section ************************************ //if comment against post not empty if (newsfeed.commentsarray.count>0) { self.commentsectioncontainer.hidden = no; float commenty=0; self.lblcomments.text = [nsstring stringwithformat:@"%lu",(unsigned long)newsfeed.commentsarray.count]; (postcomment *comment in newsfeed.commentsarray) { commentsection *commentview = [[[nsbundle mainbundle] loadnibnamed:@"textcomment" owner:nil options:nil] objectatindex:0]; commentview.editcommentview.txtcomment.delegate = self; commentview.tag = 1000+[newsfeed.commentsarray indexofobject:comment]; commentview.userinteractionenabled = yes; [commentview.profileimg setupimageviewer]; commentview.profilename.text = comment.username; [self commentnamesettingwithlabel:(tttattributedlabel *)commentview.profilename]; cgsize stringsize = [comment.username sizewithfont:[uifont boldsystemfontofsize:14]]; [commentview.profilename setframe:cgrectmake(commentview.profilename.frame.origin.x, commentview.profilename.frame.origin.y, stringsize.width+5, commentview.profilename.frame.size.height)]; commentview.profilename.shadowcolor = [uicolor clearcolor]; commentview.lblcomenttime.frame = cgrectmake(commentview.profilename.frame.origin.x+commentview.profilename.frame.size.width, commentview.lblcomenttime.frame.origin.y, commentview.lblcomenttime.frame.size.width, commentview.lblcomenttime.frame.size.height); //set comment time here commentview.lblcomenttime.text = [self timeleftsincedate:[self getdatefromstring:comment.created_at]]; [commentview.profileimg sd_setimagewithurl:[nsurl urlwithstring:comment.userprofileimg] placeholderimage:[uiimage imagenamed:@"avatar"]]; if (comment.iseditcomment) { //add edit view edit comment commentview.editcommentview.txtcomment.layer.bordercolor = [uicolor lightgraycolor].cgcolor; commentview.editcommentview.txtcomment.layer.borderwidth = 0.5; commentview.lblcommenttext.hidden = yes; commentview.editcommentview.hidden = no; commentview.editcommentview.txtcomment.editable = yes; commentview.lblcommenttext.text = comment.text; commentview.editcommentview.txtcomment.text = comment.text; cgsize comentrect =[commentview.lblcommenttext suggestedframesizetofitentirestringconstrainedtowidth:commentview.frame.size.width]; [commentview.editcommentview.txtcomment setframe:cgrectmake(commentview.editcommentview.txtcomment.frame.origin.x, commentview.editcommentview.txtcomment.frame.origin.y, commentview.editcommentview.txtcomment.frame.size.width, comentrect.height+15)]; [commentview.editcommentview setframe:cgrectmake(commentview.editcommentview.frame.origin.x, commentview.editcommentview.frame.origin.y, commentview.editcommentview.frame.size.width, commentview.editcommentview.txtcomment.frame.origin.y+commentview.editcommentview.txtcomment.frame.size.height)]; [commentview setframe:cgrectmake(self.sharingsection.frame.origin.x, commenty, self.frame.size.width, commentview.editcommentview.frame.origin.y+commentview.editcommentview.frame.size.height+10)]; commentview.editcommentview.userinteractionenabled = yes; if(commentview.editcommentview.txtcomment.iseditable){ [commentview.editcommentview.txtcomment becomefirstresponder]; } }else{ commentview.lblcommenttext.hidden = no; commentview.editcommentview.hidden = yes; commentview.lblcommenttext.text = comment.text; cgsize comentrect =[commentview.lblcommenttext suggestedframesizetofitentirestringconstrainedtowidth:commentview.frame.size.width-20]; //coment frame setting [commentview.lblcommenttext setframe:cgrectmake(commentview.lblcommenttext.frame.origin.x, commentview.lblcommenttext.frame.origin.y, commentview.lblcommenttext.frame.size.width, comentrect.height)]; [commentview setframe:cgrectmake(self.sharingsection.frame.origin.x, commenty, self.frame.size.width, commentview.lblcommenttext.frame.origin.y+commentview.lblcommenttext.frame.size.height+10)]; } commentview.userinteractionenabled = yes; if (comment.commentuserid == [connectionmanager getinstance].userprofile.user_id) { //long press edit or deleted comment uilongpressgesturerecognizer *cmttap = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(commenteditordelete:)]; [commentview addgesturerecognizer:cmttap]; } commenty = commentview.frame.origin.y+commentview.frame.size.height; commentview.sepratorview.frame = cgrectmake(0, commentview.frame.size.height-1, commentview.frame.size.width, 1); [self.commentsectioncontainer addsubview:commentview]; self.commentsectioncontainer.frame = cgrectmake(self.commentsectioncontainer.frame.origin.x, yposition, self.frame.size.width, commentview.frame.origin.y+commentview.frame.size.height); [self setcommentlabelfontwitlabel:commentview.lblcommenttext]; } yposition = self.commentsectioncontainer.frame.origin.y+self.commentsectioncontainer.frame.size.height; }else{ self.commentsectioncontainer.hidden = yes; self.lblcomments.text = @"0"; } //***************************post comment section ************************************ self.txtcomentview.text = @""; //self.postcommentsection.layer.borderwidth = 1.0; //self.postcommentsection.layer.bordercolor = [uicolor redcolor].cgcolor; self.postcommentsection.frame = cgrectmake(self.postcommentsection.frame.origin.x, yposition, self.postcommentsection.frame.size.width, self.postcommentsection.frame.size.height); yposition = self.postcommentsection.frame.origin.y+self.postcommentsection.frame.size.height; self.celltotalheight = yposition; [self settweetlabelfont];
}
finally solved problem creating 3 different xib files iphone 5, 6 , 6 plus.
Comments
Post a Comment