ios - dynamic cell height based on labels -


i have started ios development , facing issue uitableview.i want create expandable cell.so after researching tried code works in phones , not phones.so wanted help.

storyboard enter image description here

at beginning wanted show first 3 labels , on click want show labels

code

//to calculate expanded height     func expandedheight() -> cgfloat         {             let data = arraydrugs[selectedindex!.row]              let cell = tableview.dequeuereusablecellwithidentifier("expandedcell") as! udcell              let height = returnlableheight(cell.lblproducts, fontsize: 16, text: data.packedprod) +                 returnlableheight(cell.lblseconddata, fontsize: 15, text: data.dose) +                 returnlableheight(cell.lblthirddata, fontsize: 15, text: data.seconddata) +                 returnlableheight(cell.lblfourthdata, fontsize: 15, text: data.thirddata) +                 returnlableheight(cell.lblfifthdata, fontsize: 15, text: data.fourthdata) +                 returnlableheight(cell.lblsixthdata, fontsize: 15, text: data.fifthdata) +                 returnlableheight(cell.lblseventhdata, fontsize: 15, text: data.sixthdata)             print(height);             print((cell.contentview.systemlayoutsizefittingsize(uilayoutfittingexpandedsize).height)+1)             cell.sizetofit()             cell.setneedslayout()             cell.layoutifneeded()              return (cell.contentview.systemlayoutsizefittingsize(uilayoutfittingexpandedsize).height);          }  //to calculate collapsed height          func collapseheight(indexpath:nsindexpath) -> cgfloat{               let data = arraydrugs[indexpath.row]              let cell = tableview.dequeuereusablecellwithidentifier("expandedcell") as! udcell              let height = returnlableheight(cell.lblproducts, fontsize: 16, text: data.packedprod) +             returnlableheight(cell.lblseconddata, fontsize: 15, text: data.dose) +             returnlableheight(cell.lblthirddata, fontsize: 15, text: data.seconddata)                //print(height);            // print((cell.contentview.systemlayoutsizefittingsize(uilayoutfittingexpandedsize).height)+1)             cell.sizetofit()             cell.setneedslayout()             cell.layoutifneeded()              return (height+120);          }  //calculate label height func returnlableheight(label:uilabel,fontsize:cgfloat,text:nsattributedstring) -> cgfloat{          label.numberoflines = 0         label.linebreakmode = nslinebreakmode.bywordwrapping         label.font = uifont.systemfontofsize(fontsize)         label.preferredmaxlayoutwidth = self.view.frame.width-40;         label.attributedtext = text //        let rect:cgrect = text.boundingrectwithsize(cgsizemake(self.view.frame.width-25,cgfloat.max), options: nsstringdrawingoptions.useslinefragmentorigin, context:nil )//hear u nearer height not exact value //        let requredsize:cgrect = rect          label.sizetofit()          //print(requredsize.height)         return label.frame.height     } 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -