我有一个可扩展的tableView,当我扩展一个部分时,其中会出现三个单元格。在第一个单元格中只有名称,而在第二个单元格中只有名称。它的内容很大。现在我想根据内容自动调整这个标签的高度和宽度。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tblView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell
let dataArrayTblView = dataArrayForTableView
let titleName = dataArrayTblView.valueForKey("name")
let dueDate = dataArrayTblView.valueForKey("deadlinedate")
let description = dataArrayTblView.valueForKey("description")
cell.titleLabel.text = titleName[indexPath.row] as AnyObject! as! String!
cell.dueDateLabel.text = dueDate[indexPath.row] as? String
cell.descriptionLabel.text = description[indexPath.row] as? String
cell.descriptionLabel.sizeToFit()
cell.textLabel?.backgroundColor = UIColor.clearColor()
cell.selectionStyle = .None
return cell
}
但没有获得完整的内容
最佳答案
尝试设置这个。它会自动为您调整行的高度。如果它不起作用,那么 Storyboard中的约束就有问题。
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 40
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
关于ios - 如何调整自定义tableView Cell中的标签高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911740/