简体   繁体   English

iOS调整UIImageView的大小以适合UILabel

[英]iOS resize UIImageView to fit for UILabel

I have a UILabel with dynamic height. 我有一个具有动态高度的UILabel。 I am trying to place it within bubble image. 我正在尝试将其放置在气泡图像中。 How do I resize UIImageView to fit for UILabel? 如何调整UIImageView的大小以适合UILabel?

You need to set 2 constraints: 您需要设置2个约束:

  • 1 constraint to force your UIImageView to have the same height as the UILabel 1个约束,强制您的UIImageView具有与UILabel相同的高度
  • 1 constraint to force your UIImageView to have the same width as the UILabel 1个约束,强制您的UIImageView具有与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个约束,以将UIImageView的中心与UILabel的中心水平对齐
  • 1 constraint to align vertically the center of your UIImageView with the center of your UILabel 1个约束,以将UIImageView的中心与UILabel的中心垂直对齐

See this documentation to learn how to add contraints programatically. 请参阅此文档以了解如何以编程方式添加约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM