我有一个动态单元格高度的问题。这是我的代码,单元格不是动态高度,hơ使它动态(不是自动布局)。感谢swift中的动态单元格高度
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) as! CustomCell
let label = UILabel(frame: CGRectMake(0 , 0, cell.frame.width, cell.frame.height))
label.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget libero enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec tempor posuere augue. Pellentesque at nibh quam. Mauris at nulla id enim elementum fermentum sit amet at dolor. Phasellus quis purus eu enim ullamcorper porttitor. Praesent consectetur lorem non ligula elementum rhoncus. Pellentesque diam dolor, gravida eget quam at, consequat luctus elit. Curabitur posuere augue sed nunc ornare semper. Nunc ut lorem vitae ligula dictum dapibus quis eget ex. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."
label.numberOfLines = 0
label.sizeToFit()
label.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.contentView.addSubview(label)
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
@shuuichiakai如果它是有用的,然后使upvote谢谢 – Jaydip