设置垂直空间iOS时,Autolayout图像被拉伸

时间:2016-06-04 07:17:06

标签: ios uiimageview autolayout

观点层次结构:

  1. UIImageView裁剪圆形:
  2. 约束:宽度,高度,顶部布局引导垂直空间,将X对齐到SuperView,将X对齐到相机按钮

    1. 相机按钮:
    2. 约束:宽度,高度,顶部空间ImageView,将中心X与ImageView对齐。

      尝试这样裁剪图像 enter image description here

      请建议避免这种情况。

1 个答案:

答案 0 :(得分:0)

你的约束应该是:

ImageView:horizontally in container, Vertically in container, fixed width, fixed height

按钮:horizontally in container(align center x) and top。如果需要那么fixed height and width(这只需要按钮不是默认值意味着自定义按钮其他明智的两个约束就足够了 - 容器和顶部水平)

然后在你的viewDidload中设置你的imageview的cornerradius,

   self.imageViewProfile.layer.cornerRadius = 26.5; //corner radius should be exact half of your imageView's height
   self.imageViewProfile.layer.masksToBounds = YES;

希望这会有所帮助:)