自动版式 - 保持图像的水平约束的比例(雨燕X code 6) [英] AutoLayout - Keep Ratio of Image With Horizontal Constraints (Swift Xcode 6)

查看:306
本文介绍了自动版式 - 保持图像的水平约束的比例(雨燕X code 6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力实现图片的时间表(如Instagram的或Facebook)。
不过,我一直在挣扎与图像的比例。

I've been trying to implement a timeline of picture (as instagram or facebook). However, I've been struggling with the ratio of the image.

下面是我的厦门国际银行,包含我的手机:

Here's my xib that contains my Cell :

我所需的图片,以保持它的比率,并完全填满的小区的宽度。
我设置了4自动布局约束上的UIImageView为0-0水平约束,5-5顶部/底部的限制。我还设置视图模式为看点适应。

I want the picture to keep its ratio and to completely fill the width of the cell. I've set 4 autolayout constraint on the UIImageView as 0-0 for horizontal constraint and 5-5 for top/bottom constraints. I've also set the ViewMode to "Aspect Fit".

我已经尝试了不同的设置:

I've tried different setup :


  1. 设置的UIImageView的高度,以一个特定的值:
    - >图像的宽度修改,以保持图像比例

  2. 请不要设置的UIImageView的高度
    - >则认为高度等于0,因此,甚至不显示图像

  3. 设置高度大于或等于特定值:
    - >相同的行为为1(图像的宽度修改,以保持图像比例)

我是从网址,所以我一直在使用的lib哈内克( HTTPS加载图像.COM /哈尼克/ HanekeSwift )具有以下功能:
imageView.hnk_setImageFromURL(URL)。

I'm loading the image from an URL so I've been using the lib Haneke (https://github.com/Haneke/HanekeSwift) with the following function : imageView.hnk_setImageFromURL(url).

它具有图像的自动调整大小,我不知道如何获得图像的原始宽度/高度手动设置的高度。

It has an automatic resize of the image and I don't know how to get the original width/height of the image to set the height manually.

再次我要的是画面保持其比例和完全填充单元格的宽度。

Again, what I want is the picture to keep its ratio and to completely fill the width of the cell.

任何人有一个建议?

非常感谢!

推荐答案

这是我想出了设置。这是一个快速和肮脏的演示,但我会假设你想要的形象总是居中。您可以在故事板设置水平和垂直居中约束始终居中
如果你想让它总是完全填充视图,可以更换等高相等宽度,但这样做,在ImageView的会,因为纵横比约束的某些尺寸超出屏幕

This is the setup I came up with. It's a quick and dirty demo, but I would assume you'd want the image to always be centered. You can set the Horizontal and Vertical Center Constraint in storyboard to always keep it centered If you want it to always completely fill the view, you can replace Equal Height with Equal Width, but by doing so, the imageView will run off the screen on some sizes because of the aspect ratio constraint

我也包括在不同尺寸的观点截图

I've also included screenshots of the view at different sizes

这篇关于自动版式 - 保持图像的水平约束的比例(雨燕X code 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆