【问题标题】:How to populate a UITableViewCell with the correct resolution image?如何用正确的分辨率图像填充 UITableViewCell?
【发布时间】:2015-02-18 07:05:03
【问题描述】:

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

我正在使用资产目录将图像命名为 image1.png、image1@2x.png 和 image1@3x.png。

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

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 平台上运行它时,图像真的很模糊,分辨率也很差。

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

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

这是我的资产目录的外观:

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

谢谢

【问题讨论】:

  • 您的 xcasset 目录的名称是什么
  • 您的图像是否在资产目录中的@2x 和@3x 占位符中正确分配?
  • 我更新了我的问题,请看。
  • 您的代码看起来应该对我有用...
  • 据我所知,模拟器从未使用过@3x,您必须在设备上运行它才能看到它们。它与像素在 6+ 上的渲染方式有关

标签: ios objective-c xcode uitableview


【解决方案1】:

您无需知道资产目录下的文件名。

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

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

你应该没事的。

【讨论】:

    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多