Updated 27 February 2019
There are the various places that we need to use launch image in our project but there is no direct way to use launch images. For this, we have two ways to do the same.
1. Putting all the launch image in Assets separately. This will increase your project size and you have to assign these images manually to UIImageView.
2. Use the same launch images used in the launch image set. I have written an extension for the same.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
struct Device { // iDevice detection code static let IS_IPAD = UIDevice.current.userInterfaceIdiom == .pad static let IS_IPHONE = UIDevice.current.userInterfaceIdiom == .phone static let IS_RETINA = UIScreen.main.scale >= 2.0 static let SCREEN_WIDTH = Int(UIScreen.main.bounds.size.width) static let SCREEN_HEIGHT = Int(UIScreen.main.bounds.size.height) static let SCREEN_MAX_LENGTH = Int( max(SCREEN_WIDTH, SCREEN_HEIGHT) ) static let SCREEN_MIN_LENGTH = Int( min(SCREEN_WIDTH, SCREEN_HEIGHT) ) static let IS_IPHONE_4_OR_LESS = IS_IPHONE && SCREEN_MAX_LENGTH < 568 static let IS_IPHONE_5 = IS_IPHONE && SCREEN_MAX_LENGTH == 568 static let IS_IPHONE_6 = IS_IPHONE && SCREEN_MAX_LENGTH == 667 static let IS_IPHONE_6P = IS_IPHONE && SCREEN_MAX_LENGTH == 736 static let IS_IPHONE_XSERIES = IS_IPHONE && SCREEN_MAX_LENGTH > 736 static func FetchLaunchImage() -> UIImage? { if Device.IS_IPHONE_4_OR_LESS { } else if Device.IS_IPHONE_5 { } else if Device.IS_IPHONE_6 { } else if Device.IS_IPHONE_6P { } else if Device.IS_IPHONE_XSERIES { } else if Device.IS_IPAD { if (UIScreen.main.scale == 1) { return UIImage(named: "LaunchImage-700-Portrait~ipad.png") } else if (UIScreen.main.scale == 2) { return UIImage(named: "LaunchImage-700-Portrait@2x~ipad.png") } } return nil } } |
Uses:
1 |
launchview.image = Device.FetchLaunchImage() |
Thank You!!!
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.