Created
May 18, 2015 02:33
-
-
Save nixzhu/3c8ed0b8f7f24df924ac to your computer and use it in GitHub Desktop.
Add screenModel to UIDevice, and we use it set UI for different iPhone models
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
import UIKit | |
extension UIDevice { | |
enum ScreenModel { | |
case Classic | |
case Bigger | |
case BiggerPlus | |
} | |
static let screenModel: ScreenModel = { | |
let screen = UIScreen.mainScreen() | |
let nativeWidth = screen.nativeBounds.size.width | |
if nativeWidth == 320 * 2 { | |
return .Classic | |
} else if nativeWidth == 375 * 2 { | |
return .Bigger | |
} else if nativeWidth == 414 * 3 { | |
return .BiggerPlus | |
} | |
return .Bigger // Default | |
}() | |
class func matchMarginFrom(classic: CGFloat, _ bigger: CGFloat, _ biggerPlus: CGFloat) -> CGFloat { | |
switch screenModel { | |
case .Classic: | |
return classic | |
case .Bigger: | |
return bigger | |
case .BiggerPlus: | |
return biggerPlus | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment