Created
June 5, 2015 15:19
-
-
Save sleroux/956482e4416abd62521e to your computer and use it in GitHub Desktop.
moz_SizeClass
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
enum moz_sizeClass { | |
case Unknown | |
case XSmall | |
case Small | |
case Medium | |
case Large | |
case XLarge | |
case XXLarge | |
case XXXLarge | |
static func sizeClassForValue(value: CGFloat) -> moz_sizeClass { | |
if value >= 0 && value <= 160 { | |
return .XSmall | |
} else if value > 160 && value <= 320 { | |
return Small | |
} else if value > 320 && value <= 375 { | |
return Medium | |
} else if value > 375 && value <= 414 { | |
return Large | |
} else if value > 414 && value <= 748 { | |
return XLarge | |
} else if value > 748 && value <= 1024 { | |
return XXLarge | |
} else if value > 1024 { | |
return XXXLarge | |
} else { | |
return .Unknown | |
} | |
} | |
} | |
extension UIView { | |
func verticalSizeClass() -> moz_sizeClass { | |
let size = systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) | |
return moz_sizeClass.sizeClassForValue(size.height) | |
} | |
func horizontalSizeClass() -> moz_sizeClass { | |
let size = systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) | |
return moz_sizeClass.sizeClassForValue(size.width) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment