iPhone 4“屏幕与xcassets没有拉正确的图像

时间:2013-09-27 17:09:30

标签: iphone ios xcode ios7 xcode5

我正在尝试将Images.xcassets应用到我正在处理的项目中。根据我的理解,我可以在那里为不同的设备放置所有不同大小的图像,然后调用[UIImage imageNamed:@“name_of_image_set”],它将返回我正在处理的设备的正确图像。

除了带有4英寸屏幕的iPhone 5 / 5s / 5c之外,似乎正在为所有内容提取正确的图像。对于该屏幕尺寸,它为我提供了带有3.5英寸屏幕的@ 2x iPhone的图像。

Image of config in Images.xcassets

这是包含在图像文件夹中的json。

{
  "images" : [
    {
      "idiom" : "iphone",
      "scale" : "1x",
      "filename" : "bg.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "filename" : "bg@2x.png"
    },
    {
      "idiom" : "iphone",
      "filename" : "bg-568h@2x.png",
      "subtype" : "retina4",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "filename" : "bg~ipad.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "filename" : "bg@2x~ipad.png"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

一切似乎都井然有序,我只是误解了xcassets应该如何运作?

由于

Joel Bell

2 个答案:

答案 0 :(得分:4)

我遇到了这个问题,问题似乎是针对低于7.0的iOS版本 对我来说,解决方案是创建一个单独的图像集,其中包含一个@ 2x图像,并通过检测代码中的iPhone屏幕大小以编程方式实例化正确的图像,如完成here

相关: Why isn't my Asset Catalog returning R4 images?

答案 1 :(得分:0)

我有同样的问题但只在ios7中我以编程方式加载图像,但它应该是同样的问题。

在我的viewDidLoad中,我添加了:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) { // if iOS 7
    self.edgesForExtendedLayout = UIRectEdgeNone; //layout adjustements
}

它基本上只识别iOS7并应用一些布局调整。添加此代码后,选择了正确的图片。 最后我加载了我的图像,你不必这样做:

 [productview setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];

在stackoverflow中也找到了这个答案,但是没有找到它。