Last active
August 29, 2015 14:15
-
-
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.
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
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