I have a UITableView in which i am displaying a custom cell.I my cell i have two label & one view as below in picture.
I have given constraint of left v
Swift 3 / Swift 4
Custom cell:
class CustomCell: UITableViewCell {
@IBOutlet var messageLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
sizeToFit()
layoutIfNeeded()
}
}
viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
And cellForRowAtIndexPath:
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : CustomCell = tableView.dequeueReusableCell(withIdentifier: "yourcellIdentifier", for: indexPath) as! CustomCell
cell.messageLabel.text = exampleContent[indexPath.row]
cell.messageLabel.sizeToFit()
cell.messageLabel.layoutIfNeeded()
return cell
}