自定义UITableViewCell中的UIImageView不尊重Aspect Fit模式 [英] UIImageView in custom UITableViewCell not respecting Aspect Fit mode

查看:101
本文介绍了自定义UITableViewCell中的UIImageView不尊重Aspect Fit模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,它使用我在NIB上创建的自定义UITableViewCell。
在这个自定义单元格中,我有一个正方形图像视图来显示徽标。
图片已经是缩略图大小但是它们有不同的尺寸(有些是正方形,有些则不是)。

I have a table view that uses a custom UITableViewCell that I created on a NIB. In this custom cell I have a square image view to show logos. The images are already thumbnail-size but they have different sizes (some are squares and some are not).

我只是在我的自定义单元格中指定了我的UIImage有一个Aspect Fit的视图模式,以便让它们全部显示在正方形上但不会失去它们的宽高比。

I simply specified my UIImage in my custom cell to have a View Mode of "Aspect Fit", so as to make all of them display on a square but without losing their aspect ratio.

问题是我保持获得一个填充我的行的高度的图像,因此矩形图像比方形图像宽。

The problem is that I keep getting an image that fills the height of my row and so the rectangle images are wider than the square images.

我错过了一些基本的东西吗?我搜索并看到很多关于调整大小和缩放的帖子,但不是特定于自定义UITableViewCell中的UIImageView。

Am I missing something basic here? I searched and saw many posts about resizing and scaling but not specific to a UIImageView in a custom UITableViewCell.

推荐答案

我有同样的问题。 UITableViewCell有一个名为imageView的UIImage。因此,如果您的UIImage变量也被命名为imageView,则所有代码都将应用于默认的UIImage。请确保自定义UITableViewCell中的UIImage变量的名称与imageView不同

I had the same problem. The UITableViewCell has a UIImage named "imageView". So if your UIImage variable is also named "imageView", all the code is applied to the default UIImage. Please make sure that the UIImage variable in your custom UITableViewCell is named something different than "imageView"

在我的代码中,我有以下行:

In my code I had the following line:

cell.imageView.image = UIImage(named: "example")

我已将UIImage变量名称更改为myImageView并将上面的代码替换为:

I have changed the UIImage variable name to "myImageView" and replaced the code above with:

cell.myImageView.image = UIImage(named: "example")

和Aspect fit模式已启动工作!

and Aspect fit mode started to work!

这篇关于自定义UITableViewCell中的UIImageView不尊重Aspect Fit模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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