如何调整一个固定的宽度和高度的UIImageView自动布局 [英] How to resize a fixed width and height UIImageView with auto layout

查看:1079
本文介绍了如何调整一个固定的宽度和高度的UIImageView自动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 MyView的视图这始终是半个屏幕,坐在屏幕的顶部。

I have a view named myView which is always half the screen and sit at the top of screen.

在这个观点我添加了一个的UIImageView 与120×120大小它坐落在中央的 MyView的(水平和垂直方向)。 IB的内部,以满足约束条件(X安培; Y)我总是需要设置一个固定的宽度和高度为我的形象,在我设置水平中心和中心垂直。

Inside this view I added an UIImageView with 120x120 size which sits in center of the myView (horizontally and vertically). Inside the IB, to satisfy the constraints(X & Y) I always need to set a fixed width and height for my image, after I set center horizontally and center vertically.

但是,有一个固定的高度和宽度,改变屏幕尺寸时,图像不调整大小。我希望我的形象上的iPhone5或iPhone 4S上运行时调整,因为 MyView的将调整。
我需要的东西,如图像应取决于 MyView的尺寸。

But with a fixed height and width, the image doesn't resize when changing the screen size. I want my image to resize when running on iPhone5 or iPhone 4s, because myView will resize. I need something like the image should depend on the myView size.

如何真正实现这一目标?

How to actually achieve this ?

推荐答案

设置 imageView.clipToBounds = YES ,并设置 imageView.contentMode = UIViewContentModeScaleAspectFit;

更新
你说的是ImageView的不是图像,在这种情况下,需要时不会调整,由于不断的宽度和高度,做一件事,创建约束的IBOutlet中,然后在那里的价值观,或者你也可以设置宽高比的SuperView

Update You are talking about imageView not the image, in that case it will not resize due to constant width and height, do one thing, create IBoutLet of constraint and change there values when required, or you can also set Aspect ratio with superView

这篇关于如何调整一个固定的宽度和高度的UIImageView自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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