iPhone - UIImageView中的UIImage [英] iPhone - Center UIImage in UIImageView

查看:142
本文介绍了iPhone - UIImageView中的UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIImageView。我从一个URL得到一个UIImage。图像显示在UIImageView中,但我无法使其正确居中。 UIImage是80 x 68像素。 UIImaveView的大小是90 x 90.当我在UIImageView中显示UIImage时,UIImage缩小,以使其适合,虽然它已经小于UIImageView。我已经尝试了所有的内容模式在IB。其中一些人将图像向上移动,使其不再在UIImageView中。这一切对我来说都没有意义。看起来UIImage应该显示在UIImageView内部,如果它已经在所需的大小。任何帮助将是巨大的。

I have a UIImageView. I get a UIImage from a URL. The image displays in the UIImageView, but I can't get it to center correctly. The UIImage is 80 x 68 pixels. The UIImaveView's size is 90 x 90. When I display the UIImage in the UIImageView the UIImage is shrunken so that it fits, although it is already smaller than the UIImageView. I have tried all the Content Modes in IB. Some of them shift the image up so that it is no longer in the UIImageView. None of this really makes sense to me. It seems that the UIImage should display inside the UIImageView fine if it is already within the required size. Any help would be great.

使用UIImageView上的中心模式

With Mode of Center on the UIImageView

使用UIImageView上的宽高比模式

With Mode of Aspect Fit on the UIImageView

使用中心,图像大小似乎正确,但你可以看到它出来的UIImageView它有一个红色的UIView下面,它实际上是2px在每一边大于图像视图。但是使用Aspect Fit,它使图像变小,使其适合内部。但是我不明白为什么它会变小,如果它已经足够小到适合。

With Center, the size of the image seems correct but you can see that it goes out of the UIImageView which has a red UIView underneath it and is actually 2px on each side larger than the image view. But with the Aspect Fit, it makes the image smaller so that it fits inside. But I don't understand why it would make it smaller if it is already small enough to fit.

推荐答案

对不起浪费任何人时间。原来我没有尝试所有的内容模式。看来底部顶部的内容模式工作。这是从我如何理解它。感谢您的帮助。

Sorry for wasting anyone's time. Turns out I didn't try all of the content modes. Seems that Content Mode of Bottom top works. This is backwards from how I understood it. Thanks for all your help.

这篇关于iPhone - UIImageView中的UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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