2016-04-17 172 views
0

我在所有尺寸(320x480 640x960 640x1136 750x1334 1242x2208)中都有相同的图像,我使用这些图像作为启动屏幕(资产 - >新iOS启动图像)。 我想在应用程序运行时使用这些图像(在UIImageView中)选择正确的图像大小屏幕使用的设备。 在启动屏幕是完美的,但如果我使用UIImageView的LaunchImage,视图中的图像是不同的。使图像适合屏幕

在这个环节有我的测试代码(Launch.zip)https://github.com/Volpesio/Launch.git 此代码运行启动图像(完美),并显示一个的UIImageView后,它应该使用发射相同的影像,但是didifferent

如何调整大小或如何为使用中的设备选择正确的图像? 你能帮助我,请..

+0

我认为这[链接](http://engineering.circle.com/fullscreen-images-on-iphone-6-with-asset-catalogs/)可能会有帮助,也许你可以尝试使用特定的约定来命名图像来解决你的问题。 –

+0

好的这个解决方案很好。 在xcode 7中没有“Retina 4 x2”,但没关系,没有问题。 如果我在LaunchImages中添加了不同大小的图像,我将为相同图像创建一个内存占用。 这些图片很大,因为它们在HD – alessiovolpe

+0

@程昱钰,感谢您的链接,这很完美。 – alessiovolpe

回答

0

我使用此代码解决了这个问题:

extension UIImage { 
    convenience init?(fullscreenNamed name: String) { 
     switch UIScreen.mainScreen().bounds.size.height { 
     case 480: //iPhone 4/4s 
      self.init(named: "\(name)[email protected]") 
     case 568: //iPhone 5/5s 
      self.init(named: "\(name)[email protected]") 
     case 667: //iPhone 6/6s 
      self.init(named: "\(name)[email protected]") 
     case 736: //iPhone 6+/6s+ 
      self.init(named: "\(name)[email protected]") 
     default: 
      self.init(named: name) 
     } 
    } 
} 

我参加“LaunchImage”在使用该设备的屏幕右侧图像