Ich habe einen TableView mit mehreren customCells und kann daher estimatedRowHeight
nicht verwenden. In dieser Zelle muss die Zeilenhöhe jedoch gleich dem Inhalt der Beschriftung innerhalb der Zelle sein. Es scheint jedoch nicht den ganzen Text zu zeigen.Höhe der Zelle gleich dem Inhalt des Etiketts einstellen
ich angefangen habe, indem cosntraints
Dann in Zelle Unterklasse gesetzt i Schrifthöhe
descLabel!.font = UIFont.systemFontOfSize(14)
Dann i die Berechnung func
func calculateHeightForString(inString:String) -> CGFloat
{
let messageString = inString
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 2
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(14.0)]
let attrString:NSMutableAttributedString? = NSMutableAttributedString(string: messageString, attributes: attributes)
attrString!.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString!.length))
let rect:CGRect = attrString!.boundingRectWithSize(CGSizeMake(self.view.frame.width-24,CGFloat.max), options: NSStringDrawingOptions.UsesLineFragmentOrigin, context:nil)//hear u will get nearer height not the exact value
let requredSize:CGRect = rect
return requredSize.height //to include button's in your tableview
}
einstellen erstellen Höhe für Abschnitt 1
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 0 {
return 160.0/320.0 * tableView.bounds.width
} else if indexPath.section == 1 {
return self.calculateHeightForString("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also th") + 24
} else {
return 100
}
}
Ergebnis, wo es nicht alles
Überprüfen Sie, wie groß die Zellenhöhe für 1 Liner ist. Wenn es das gleiche wie oben ist, scheint die Einschränkung falsch zu sein. –