Dynamic Height Issue for UITableView Cells (Swift)

前端 未结 25 2536
温柔的废话
温柔的废话 2020-11-28 04:39

Dynamic text of variable length are being injected into tableview cell labels. In order for the tableview cells\' heights to be dynamically sized, I have implemented in

25条回答
  •  遥遥无期
    2020-11-28 05:08

    Swift 5 Enjoy

    tablev.rowHeight = 100
    tablev.estimatedRowHeight = UITableView.automaticDimension
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = self.tablev.dequeueReusableCell(withIdentifier: "ConferenceRoomsCell") as! ConferenceRoomsCell
        cell.lblRoomName.numberOfLines = 0
        cell.lblRoomName.lineBreakMode = .byWordWrapping
        cell.lblRoomName.text = arrNameOfRooms[indexPath.row]
        cell.lblRoomName.sizeToFit()
        return cell
    }
    

提交回复
热议问题