Created
July 25, 2016 11:50
-
-
Save AnselmeKotchap/a27cb46d29867a0159a301ecf9e84e8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIDevice { | |
var iPhone: Bool { | |
return UIDevice().userInterfaceIdiom == .Phone | |
} | |
enum ScreenType: String { | |
case iPhone4 | |
case iPhone5 | |
case iPhone6 | |
case iPhone6Plus | |
case Unknown | |
} | |
var screenType: ScreenType? { | |
guard iPhone else { return nil } | |
switch UIScreen.mainScreen().nativeBounds.height { | |
case 960: | |
return .iPhone4 | |
case 1136: | |
return .iPhone5 | |
case 1334: | |
return .iPhone6 | |
case 2208: | |
return .iPhone6Plus | |
default: | |
return nil | |
} | |
} | |
} | |
print(UIDevice().screenType) | |
//source: http://stackoverflow.com/questions/27775779/how-to-check-screen-size-of-iphone-4-and-iphone-5-programmatically-in-swift |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment