You should use UITableViewAutomaticDimension provides a solution for displaying dynamic content.
Use below code in viewDidLoad:
tableView.estimatedRowHeight = YourTableViewCellHeight
tableView.rowHeight = UITableView.automaticDimension
Read more from here
Hope it helps. :)