Reputation: 193
I want to make a dynamic imageView which can depend on the image ratio inside(image's ratio different). And the imageView width follow the screen width(or the tableView width), image's height is resize by the image inside. My storyboard looks like that:
The imageView mode set Aspect Fit. How can the image's width be the same with tableView(or screen width)? And to resize both the height of the image and tableView ??(don't leave yellow margin)
Upvotes: 1
Views: 564
Reputation: 3657
Don't fix the height and width of imageView. Using constraints just set the x, y position, it automatically becomes resizable according to image size.
Upvotes: 1
Reputation: 407
I suggest you add a Y constraint, e.g. use the pin board to constraint the vertical spacing to top layout guide, and then use control drag to the view controller icon, to centre the imageView horizontally, then when you set the image for the imageView, it should automatically resize to the size that the image is as you won't have set any size or aspect ratio constraints. If you wanted, you could set a constraint to say you always want it to be an equal height from the table view, however, this could cause the image to look stretched if you do not set the aspect ratio.
Upvotes: 0