Skip to content

Instantly share code, notes, and snippets.

@anirudhamahale
Created July 19, 2017 04:21
Show Gist options
  • Save anirudhamahale/58f60a4c7e7ab191e46fc7b9bba279a8 to your computer and use it in GitHub Desktop.
Save anirudhamahale/58f60a4c7e7ab191e46fc7b9bba279a8 to your computer and use it in GitHub Desktop.
Trick when some of the content of the UITableViewCell's get chopped.
/*
When we give dynamic height for the UITableViewCell, sometimes the below line gets truncated, by doing this it can be prevented.
*/
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NotifyTableViewCell") as! NotifyTableViewCell
cell.bounds = CGRect(x: 0, y: 0, width: tableView.bounds.width * 0.9, height: 99999)
cell.contentView.bounds = cell.bounds
cell.layoutIfNeeded()
cell.titleLabel.text = notifications[indexPath.section].title
cell.titleLabel.preferredMaxLayoutWidth = cell.titleLabel.frame.width
cell.descriptionLabel.text = notifications[indexPath.section].message
cell.descriptionLabel.preferredMaxLayoutWidth = cell.descriptionLabel.frame.width
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment