3

I've created a label in a tableViewCell which contain a string of text. The size of the string can vary however it should maximum be 3 lines. However i can't seem to do this? What is the easiest way to create such a functionality in this label so far i've just created this label in my tableViewCell Subclass.

 @IBOutlet weak var dummyLabel: UILabel!
Peter Pik
  • 10,783
  • 18
  • 79
  • 134

1 Answers1

3

In your custom UITableViewCell class add this:

override func layoutSubviews() {
    super.layoutSubviews()
    dummyLabel.sizeToFit()
}

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    dummyLabel.numberOfLines = 3
}

Similar post here about label resize in UITableViewCell: Swift : align UILabel text in the top rather in the middle

Community
  • 1
  • 1
Caleb
  • 5,402
  • 2
  • 23
  • 32