ios - Swift: Cannot get correct height of header cell's label after sizetofit -
i have add sizetofit()
uilabel, cannot correct height cannot show text. show "academic, administrative, teaching and"
testing target: iphone 6
coding:
class eventsviewcontroller: uitableviewcontroller { var headername: array<string> = ["academic, administrative, teaching , learning support units"] override func viewdidload() { self.tableview = uitableview(frame: self.tableview.frame, style: .grouped) self.view.backgroundcolor = uicolor(white: 0.9, alpha: 1.0) self.tableview.estimatedrowheight = 102 } override func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? { var headercell = tableview.dequeuereusablecellwithidentifier("eventsheadercell") as! uitableviewcell! if headercell == nil { headercell = uitableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "eventsheadercell") } headercell!.backgroundcolor = uicolor(white: 0.9, alpha: 1.0) headercell!.textlabel?.text = headername[section] headercell!.textlabel?.numberoflines = 0 headercell!.textlabel?.linebreakmode = .bywordwrapping headercell!.textlabel?.sizetofit() headercell!.userinteractionenabled = false; headercell!.sizetofit() return headercell! } override func numberofsectionsintableview(tableview: uitableview) -> int { return headername.count } override func tableview(tableview: uitableview, heightforheaderinsection section: int) -> cgfloat { var headerlabel:uilabel = uilabel() headerlabel.text = headername[section] headerlabel.numberoflines = 0 headerlabel.linebreakmode = .bywordwrapping headerlabel.sizetofit() return headerlabel.frame.size.height } }
the problem non-break long text cause getting non-break uilabel height after sizetofit()
. but, shows text has been break in iphone 6 ios 8.
override func tableview(tableview: uitableview, heightforheaderinsection section: int) -> cgfloat { var headerlabel:uilabel = uilabel() var newline: cgfloat = 1 headerlabel.text = headername[section] headerlabel.numberoflines = 0 headerlabel.linebreakmode = .bywordwrapping headerlabel.sizetofit() if self.view.frame.width <= headerlabel.frame.width { newline = ceil(headerlabel.frame.width/self.view.frame.width) } let tblheaderheight = (headerlabel.frame.size.height * newline) + ios7_8info.geteventheadercellspacingheight() cgfloat return tblheaderheight }
Comments
Post a Comment