如何用正确的分辨率图像填充 UITableViewCell? [英] How to populate a UITableViewCell with the correct resolution image?

查看:22
本文介绍了如何用正确的分辨率图像填充 UITableViewCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个包含图像单元格的 UITableView.

I have set up a UITableView that contain cells of images.

我使用资产目录将图像适当地命名为 image1.png、image1@2x.png 和 image1@3x.png.

I am using Asset Catalog to name the images appropriately as image1.png, image1@2x.png, and image1@3x.png.

我有一个 NSMutableArray,我用资产目录中的图像名称初始化它,例如:

I have an NSMutableArray that I initialize with the image names from Asset Catalog, for example like so:

viewDidLoad:

viewDidLoad:

self.LogoArray = [ [NSMutableArray alloc] initWithObjects:@"image1",@"image2", image2", nil];

然后我用我自己的自定义图像创建了一个自定义单元格以在单元格中显示:

Then I created a Custom Cell with my own custom image to display in the cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // some code here

    cell.customImageView.image = [UIImage imageNamed:[self.LogoArray objectAtIndex:indexPath.row] ];

    // some code here
}

问题是当我在不同的 iPhone 平台上运行它时,图像非常模糊,分辨率也很差.

The problem is when I run this on the different iPhone platforms, the images are really blurry and resolution is bad.

我相信编译器不知道基于什么 iPhone 平台将哪个版本的 image.png、image@2x.png 或 image@3x.png 分配给 cell.customImageView.image它正在运行.

I believe the compiler doesn't know which version of image.png, image@2x.png, or image@3x.png to assign to cell.customImageView.image based on what iPhone platform it is running on.

我是否应该使用另一种替代方法来让 Xcode 从资产目录中选择合适的图像文件,以便在不同的 iPhone 平台上正确显示它?

Is there another alternative I should be using to allow Xcode to choose the appropriate image file from Asset Catalog to display it correctly on the different iPhone platforms?

这是我的资产目录的样子:

This is how my Asset Catalog looks:

LogoArray 中的对象使用资产目录中的正确名称进行适当命名.

The objects in the LogoArray are named appropriately with the correct name from Asset Catalog.

谢谢

推荐答案

您无需知道 Asset Catalog 下的文件名.

You don't need to know the name of the file under the Asset Catalog.

在您发送的屏幕截图中,您应该只使用名称:

In the screenshot you sent, you should just use the names:

self.LogoArray = [[NSArray alloc] initWithObjects:@"barona_logo", @"chase_logo", @"crabhut_logo", nil];

你应该没事.

这篇关于如何用正确的分辨率图像填充 UITableViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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