Skip to content

Instantly share code, notes, and snippets.

@AnselmeKotchap
Created July 25, 2016 11:50
Show Gist options
  • Save AnselmeKotchap/a27cb46d29867a0159a301ecf9e84e8f to your computer and use it in GitHub Desktop.
Save AnselmeKotchap/a27cb46d29867a0159a301ecf9e84e8f to your computer and use it in GitHub Desktop.
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