Skip to content

Instantly share code, notes, and snippets.

@klaas
Last active January 31, 2016 21:29
Show Gist options
  • Save klaas/cb8e9bbee4bdab9c59e8 to your computer and use it in GitHub Desktop.
Save klaas/cb8e9bbee4bdab9c59e8 to your computer and use it in GitHub Desktop.
View orientation
// 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