user2003416
user2003416

Reputation: 159

iOS resize UIImageView to fit for UILabel

I have a UILabel with dynamic height. I am trying to place it within bubble image. How do I resize UIImageView to fit for UILabel?

Upvotes: 1

Views: 86

Answers (1)

Quentin Hayot
Quentin Hayot

Reputation: 7876

You need to set 2 constraints:

  • 1 constraint to force your UIImageView to have the same height as the UILabel
  • 1 constraint to force your UIImageView to have the same width as the UILabel

Additionally, you may want to add the following constraints:

  • 1 constraint to align horizontally the center of your UIImageView with the center of your UILabel
  • 1 constraint to align vertically the center of your UIImageView with the center of your UILabel

See this documentation to learn how to add contraints programatically.

Upvotes: 2

Related Questions