动态更改TableView单元格高度 [英] Dynamically change TableView Cell height
本文介绍了动态更改TableView单元格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Swift / Objective C - 动态更改TableView单元格高度的简单方法
在我的表格视图中,单元格中断第一行和第三行,每个标签都是动态的
In my table view cell break first line and third line, every label will dynamic
推荐答案
向图像视图添加约束(顶部,前导,尾随,高度)
不要添加底部限制条件
添加每个标签的限制(顶部,前导,尾随,底部)
向最后一个标签添加约束(顶部,前导,尾随,底部)
设置每个标签
行数= 0
换行模式= 单词变形
表格视图数据源和委托方法
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("PropertyListCell", forIndexPath: indexPath) as UITableViewCell!
imgProperty = viewBg.viewWithTag(111) as! RemoteImageView
lblPropertyName = viewBg.viewWithTag(112) as! UILabel
lblPrice = viewBg.viewWithTag(113) as! UILabel
lblAddress = viewBg.viewWithTag(114) as! UILabel
lblAreaPerSquare = viewBg.viewWithTag(115) as! UILabel
imgProperty.imageURL = NSURL(string: "Image Url")
lblPropertyName.text="Jai Maharashtra Apartment"
lblPrice.text="Rs. 900 - 10000"
lblAddress.text="411041,Maharashtra Sadan, Pune, Maharashtra , India" // just address changed.
lblAreaPerSquare.text="500 Square Meter"
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 44.0
}
现在所有标签都是动态
这篇关于动态更改TableView单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文