0

I have the same image in all size(320x480 640x960 640x1136 750x1334 1242x2208) and I use these image for Launch Screen ( Assets -> New iOS Launch Image). I would like to use these image(in UIImageView) in run time of the app selecting the image proper for size screen the device in use. In Launch Screen is perfect, but if I use the LaunchImage for UIImageView, the image in view is different.

In this link there is my test code(Launch.zip) https://github.com/Volpesio/Launch.git This code run the Launch Image(perfectly) and after it displays one UIImageView, it should use the same image of Launch but is didifferent

How can I resize or how can I select the right image for the the device in use? You can help me, please..

Phocs
  • 2,430
  • 5
  • 18
  • 35
  • I think this [link](http://engineering.circle.com/fullscreen-images-on-iphone-6-with-asset-catalogs/) might be helpful, maybe you can try to name the images using certain convention to solve your problem. – Cheng-Yu Hsu Apr 17 '16 at 23:37
  • Ok this solution is good. In xcode 7 there isn't "Retina 4 x2" but it's ok, there aren't problem. If I insert images for different size in addition to the images in LaunchImages, I'll create an occupation of memory for same images. These images are large because they are in HD – Phocs Apr 18 '16 at 11:43
  • @Cheng-Yu Hsu, thanks for your link, it was perfect. – Phocs Apr 18 '16 at 17:34
  • Visit http://stackoverflow.com/a/36700644/6193113 This is the solution!!! – Phocs Apr 18 '16 at 18:47

1 Answers1

0

I solved it with this code:

extension UIImage {
    convenience init?(fullscreenNamed name: String)  {
        switch UIScreen.mainScreen().bounds.size.height {
        case 480: //iPhone 4/4s
            self.init(named: "\(name)-700@2x.png")
        case 568: //iPhone 5/5s
            self.init(named: "\(name)-700-568h@2x.png")
        case 667: //iPhone 6/6s
            self.init(named: "\(name)-800-667h@2x.png")
        case 736: //iPhone 6+/6s+
            self.init(named: "\(name)-800-Portrait-736h@3x.png")
        default:
            self.init(named: name)
        }
    }
}

I take in "LaunchImage" the right image for the device screen in use

Phocs
  • 2,430
  • 5
  • 18
  • 35