Swift iOS tableView static cell动态计算高度
2017-07-07 14:58
525 查看
TableView是iOS开发中经常使用的组件。有些表格由于UILabel包括的文本字数不一样,须要显示的高度也会不同,因此须要动态计算static cell的高度。我用的是static cell,注意每行的高度都须要指定,默认样式的cell高度是44,第三行(row == 2)进行了动态计算。第四行须要依据是否有内容推断是否显示,没有则返回高度0。
依据实际尝试和查看国外文章。发现
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) 对于静态表格好像没有作用。也有可能是我没有弄清楚正确使用方法。
依据实际尝试和查看国外文章。发现
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) 对于静态表格好像没有作用。也有可能是我没有弄清楚正确使用方法。
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { if indexPath.row == 2 { return heightForView(task.summary!, font: UIFont(name: "Helvetica", size: 15.0)!, width: 340) + 30 } else if indexPath.row == 3 { if task.type == TaskType.TYPE_PLAN.rawValue { if let descr = task.descr { return heightForView(descr, font: UIFont(name: "Helvetica", size: 15.0)!, width: 340) + 30 } } else { return 0 } } else if indexPath.row == 4 { return 110 } return 44 } // 计算高度 func heightForView(text:String, font:UIFont, width:CGFloat) -> CGFloat{ let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max)) label.numberOfLines = 0 label.lineBreakMode = NSLineBreakMode.ByWordWrapping label.font = font label.text = text label.sizeToFit() return label.frame.height }
相关文章推荐
- Swift iOS tableView static cell动态计算高度
- tableviewcell 动态计算cell高度导致tableview滑动卡顿怎么办??
- ios开发笔记之如何让tableView根据文本内容动态改变cell的高度
- IOS tableView cell动态高度 (autoLayout)
- 【iOS知识学习】_iOS动态改变TableView Cell高度
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- ios tableview 自动计算cell高度
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 【iOS知识学习】_iOS动态改变TableView Cell高度
- [iOS]在tableview中用动画效果改变cell的高度
- 基于MVC的自动计算Cell高度的TableView的使用
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- iOS UITableView Cell动态高度(使用AutoLayout)
- iOS开发动态计算cell的高度
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- iOS8 计算Cell高度的TableView实现方案
- iOS学习之-Cell动态高度计算
- iOS UITableView Cell的动态高度实现
- swift tableview cell自适应高度
- iOS 动态计算UITableViewCell 高度 以及计算UILable 高度 自定义Cell