Skip to content

Instantly share code, notes, and snippets.

@nixzhu
Created May 18, 2015 02:33
Show Gist options
  • Save nixzhu/3c8ed0b8f7f24df924ac to your computer and use it in GitHub Desktop.
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
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