Reputation: 67
I have created a UIView, and inside of this view there is a label with a image above the label. The view looks like this: (don't mind the other labels on the side):
For the label that says "title" I wanted to make it so the height of it would be the height of the text, this is the code I used:
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.ByWordWrapping
The problem is that because of the image above it, the text will always stay as just one line... My plan was that the image will resize based on how tall the text is, keeping its 3:4 aspect ratio using a constraint. I'm not sure why this doesn't work , but I think it's because of the constraints on the two elements.
These are the current constraints on the views:
label:
imageView (the trailing constraint is not the issue):
Thanks!
Upvotes: 0
Views: 199
Reputation: 534893
My plan was that the image will resize
The image view has a fixed leading constraint, a fixed trailing constraint, a fixed top, and a fixed aspect ratio. Therefore it cannot resize. You have absolutely determined its size.
I had no difficulty doing what I think you describing, with no code at all (just autolayout — the label text size is changed through dynamic text):
Upvotes: 1