Last active
January 31, 2016 21:29
-
-
Save klaas/cb8e9bbee4bdab9c59e8 to your computer and use it in GitHub Desktop.
View orientation
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
// Swift version of: https://gist.github.com/smileyborg/a5d1355773ad2ba6bb1e | |
public enum ViewOrientation { | |
case Portrait | |
case Landscape | |
} | |
extension UIView { | |
public class func viewOrientationForSize(size:CGSize) -> ViewOrientation { | |
return (size.width > size.height) ? .Landscape : .Portrait | |
} | |
public var viewOrientation:ViewOrientation { | |
return UIView.viewOrientationForSize(self.bounds.size) | |
} | |
public func isViewOrientationPortrait() -> Bool { | |
return self.viewOrientation == .Portrait | |
} | |
public func isViewOrientationLandscape() -> Bool { | |
return self.viewOrientation == .Landscape | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment