我有一個動態單元格高度的問題。這是我的代碼,單元格不是動態高度,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