如何在Swift中水平放置所有iOS设备的标签

我不知道如何在图像视图中将标签水平居中,标签上写着: "You've been here. What would you rate us ,我想要What would you rate usWhat would you rate us "You've been here."我试图做到的是在标签上添加2行,select标签加上3个button,然后点击”添加缺less约束“,当我运行这个程序时,结果是这样的。

我如何解决这个问题,以便在所有设备上input文字?

在这里输入图像说明

约束

在这里输入图像说明

为您的标签尝试添加约束,如:

添加顶部,宽度和高度限制,如下面的屏幕截图所示,并确保对边距的限制不被选中。

在这里输入图像说明

并设置水平中心约束。

在这里输入图像说明

点击标签

 1.Don't set any heights 2.Now set top space to the container view 3.centre horizontal to container view 4.now set the height (or) bottom space to the smiley Add this all constraints you will get what you expected :) 

在这里输入图像说明

  1. 为特定的图像视图添加垂直顶部间距
  2. 在相同的图像视图中添加中心水平
  3. 然后像拖放方式一样调整前后距。 这很简单。

只是使用这个代码:

 yourLabel.translatesAutoresizingMaskIntoConstraints = YES; CGPoint centerPoint = yourLabel.center; centerPoint.x = yourImageView.center.x; yourLabel.center = centerPoint;