Skip to content

Instantly share code, notes, and snippets.

@danielgalasko
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgalasko/28edd24c8a0dc8341457 to your computer and use it in GitHub Desktop.
Save danielgalasko/28edd24c8a0dc8341457 to your computer and use it in GitHub Desktop.
Detect if a UIView has a Regular Width (Supports iOS 7). Sometimes its useful to run certain code depending on whether the device has a regular width.
extension UIView {
/// Returns a boolean indicating whether the view's width is currently in regular mode
/// On iOS 7 this will return true when the device is an iPad and false on iPhone
func isHorizontalSizeClassRegularWidth () -> Bool{
if self.respondsToSelector("traitCollection") {
return self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClass.Regular
} else {
return UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment