Created
July 21, 2016 11:02
-
-
Save artemkrachulov/f9426c7d66b9dceb3c26028ed26e5b2d to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// Device+screenSize.swift | |
// Extension for DeviceKit (https://github.com/dennisweissmann/DeviceKit) | |
// https://github.com/artemkrachulov/Device-screenSize | |
// | |
// Created by Artem Krachulov. | |
// Copyright (c) 2016 Artem Krachulov. All rights reserved. | |
// http://www.artemkrachulov.com | |
// | |
import UIKit | |
extension Device { | |
/// This extension property allow to control screen sizes with DeviceKit. | |
/// Return value in inches | |
/// | |
/// Usage: | |
/// | |
/// let device = Device() | |
/// | |
/// print(device) // prints, for example, "iPhone 6 Plus" | |
/// print(device.screenSize) // prints "5.5" (inches) | |
/// | |
/// if device.screenSize > Device.iPhone6.screenSize { | |
/// // Do something | |
/// } else { | |
/// // Do something else | |
/// } | |
/// | |
public var screenSize: CGFloat { | |
switch self { | |
case .iPhone4, | |
.iPhone4s, | |
.Simulator(.iPhone4), | |
.Simulator(.iPhone4s): | |
return 3.5 | |
case .iPodTouch5, | |
.iPodTouch6, | |
.iPhone5, | |
.iPhone5c, | |
.iPhone5s, | |
.Simulator(.iPodTouch5), | |
.Simulator(.iPodTouch6), | |
.Simulator(.iPhone5), | |
.Simulator(.iPhone5c), | |
.Simulator(.iPhone5s): | |
return 4.0 | |
case .iPhone6, | |
.iPhone6s, | |
.Simulator(.iPhone6), | |
.Simulator(.iPhone6s): | |
return 4.7 | |
case .iPhone6Plus, | |
.iPhone6sPlus, | |
.Simulator(.iPhone6Plus), | |
.Simulator(.iPhone6sPlus): | |
return 5.5 | |
case .iPad2, | |
.iPad3, | |
.iPad4, | |
.iPadAir, | |
.iPadAir2, | |
.Simulator(.iPad2), | |
.Simulator(.iPad3), | |
.Simulator(.iPad4), | |
.Simulator(.iPadAir), | |
.Simulator(.iPadAir2): | |
return 9.7 | |
case .iPadMini, | |
.iPadMini2, | |
.iPadMini3, | |
.iPadMini4, | |
.Simulator(.iPadMini), | |
.Simulator(.iPadMini2), | |
.Simulator(.iPadMini3), | |
.Simulator(.iPadMini4): | |
return 7.9 | |
case .iPadPro, | |
.Simulator(.iPadPro): | |
return 12.9 | |
default: | |
return 12.9 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment