Here is the screenshot of UIView with its constraints.
It is located in a tableview cell
When I use UIlabel without UIView I can get it to grow multiline. But It doesn't work with UIView which I use for padding
I tried sth like
cell.layoutIfNeeded()
cell.label.sizeToFit()
cell.label.layoutIfNeeded()
cell.view.layoutIfNeeded()
cell.view.sizeToFit()
How can I make multiline work?
And btw. - If all you need is the grey background that visually wraps the label by some constant, the label doesn't have to be a subview of that grey background view, just set the view's edges to the label's ones and do some layout corrections to fit your needs.
1 .Set background color from attribute inspector for Label.Don't use background view for label.
2 .Set UIlabel's lines property to no of lines that you want.
3 .Don't give height constraints.give only top leading trailing and width.
1- Set UIlabel's lines property to no of lines that you want, you can set it to 0, then the UILabel will automatically resize
2- Don't give height constraints, give only top leading trailing and width
3-return in heightForRowAtIndexPath: UITableView.automaticDimension (Swift 4.2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.