【发布时间】:2017-03-14 06:12:25
【问题描述】:
我正在尝试根据内容大小动态更改 tableView 单元格高度,但出现错误。
错误-
实际代码-
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
let height:CGFloat = self.calculateHeightForString(downloadTableDataa[indexPath.row] as! String)
return height + 70.0
}
func calculateHeightForString(inString:String) -> CGFloat
{
let messageString = inString
let attributes = UIFont.init(name: "Roboto-Regular", size: 15)
let attrString:NSAttributedString? = NSAttributedString(string: messageString, attributes: attributes)
let rect:CGRect = attrString!.boundingRectWithSize(CGSizeMake(300.0,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
}
【问题讨论】:
标签: swift string uitableview uifont