How can I make a UIlabel Wrap as many times as needed based on a comment text given to it?
I have tried many things like:
self.commentText.contentMode = .scaleToFill
self.commentText.numberOfLines = 0
// self.commentText.leadingMargin(pixel: 10)
// self.commentText.trailingMargin(pixel: 10)
Which I got from [Qs like.] and UILabel - auto-size label to fit text?1
But am not able to make the wrapping work
How I setup:
private func setupTheCommentText() {
self.commentText.frame = CGRect(x: 85, y: 35, width: 272, height: 15)
self.commentText.textColor = UIColor(red: 92/255, green: 92/255, blue: 92/255, alpha: 1)
self.commentText.font = UIFont(name: "SFCompactDisplay-Medium", size: 13)
//self.commentText.numberOfLines = 0
//self.commentText.contentMode = .scaleAspectFill
//self.commentText.translatesAutoresizingMaskIntoConstraints = false
// self.commentText.leadingMargin(pixel: 10)
// self.commentText.trailingMargin(pixel: 10)
self.addSubview(commentText)
self.commentText.topAnchor.constraint(equalTo:username.bottomAnchor).isActive = true
commentText.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
self.commentText.topAnchor.constraint(equalTo:username.bottomAnchor),
self.commentText.leadingAnchor.constraint(equalTo:self.contentView.leadingAnchor,constant:85.0),
self.commentText.trailingAnchor.constraint(equalTo:self.contentView.trailingAnchor,constant:-15.0),//,constant:-85.0
self.commentText.bottomAnchor.constraint(equalTo:commentText.bottomAnchor)
])
}