【问题标题】:Autolayout image stretched when set the vertical spaces iOS [duplicate]设置垂直空间iOS时自动布局图像拉伸[重复]
【发布时间】:2016-06-04 07:17:05
【问题描述】:

视图层次结构:

  1. UIImageView 裁剪为圆形:

约束:Width、Height、Top Layout Guide垂直空间、Align X to SuperView、Align X to Camera Button

  1. 相机按钮:

约束:Width、Height、Top space ImageView、Align center X to ImageView。

尝试这样裁剪图像

请建议避免这种情况。

【问题讨论】:

    标签: ios uiimageview autolayout


    【解决方案1】:

    你的约束应该是这样的:

    图像视图: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;
    

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 2017-04-22
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多