ios - 如何使用正确的分辨率图像填充 UITableViewCell?

标签 ios objective-c xcode uitableview

我已经设置了一个包含图像单元格的 UITableView。

我正在使用 Asset Catalog 将图像适当命名为 image1.png、image1@2x.png 和 image1@3x.png。

我有一个 NSMutableArray,我使用 Asset Catalog 中的图像名称进行初始化,例如:

viewDidLoad:

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

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

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

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

    // some code here
}

问题是当我在不同的 iPhone 平台上运行它时,图像真的很模糊而且分辨率很差。

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

我应该使用另一种替代方法来允许 Xcode 从 Assets 目录中选择适当的图像文件以在不同的 iPhone 平台上正确显示它吗?

这是我的 Assets 目录的样子: enter image description here

LogoArray 中的对象使用 Asset Catalog 中的正确名称进行适当命名。

谢谢

最佳答案

您不需要知道 Assets 目录下文件的名称。

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

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

你应该没问题。

关于ios - 如何使用正确的分辨率图像填充 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27564450/

相关文章:

ios - 如何在 collectionView 单元格中设置 NSLayoutConstraint 常量?

ios - UISearchBar 在关闭后正在调整大小

swift - Storyboard约束不影响自定义 UiView 大小

iOS:使用 Switch Case 检查字符串前缀?

objective-c - 如何调整 UIView 的大小并强制其 subview 调整大小

xcode - 使用Swift通过ssh向树莓派发送命令

ios - 初始化 block 内的对象

ios - 将 Pod 框架转换为最新的 Swift 版本

objective-c - Objective-C 中的类属性列表

ios - 将 curl 命令转换为 AFNetworking 调用