Last active
August 29, 2015 14:04
-
-
Save ericrowe/43af7e75f9c08d410aab to your computer and use it in GitHub Desktop.
Trait collection patch for iOS7 and Swift
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
// put these functions in an objc class, then you can call them from Swift without the link errors | |
// you'll need an owningViewController ivar passed in during init | |
-(id)init:(UIViewController*) viewController { | |
if ((self = [super init])) { | |
owningViewController = viewController; | |
} | |
return self; | |
} | |
-(UIUserInterfaceSizeClass)verticalSizeClass { | |
if ([owningViewController.view respondsToSelector:@selector(traitCollection)]) { | |
return owningViewController.view.traitCollection.verticalSizeClass; | |
} else { | |
if (([FC_Settings sharedFC_Settings].deviceType == iPad) || ([FC_Settings sharedFC_Settings].deviceType == iPadRetina)) | |
return UIUserInterfaceSizeClassRegular; | |
else { | |
if (owningViewController.interfaceOrientation == UIDeviceOrientationPortrait) { | |
return UIUserInterfaceSizeClassRegular; | |
} else { | |
return UIUserInterfaceSizeClassCompact; | |
} | |
} | |
} | |
} | |
-(UIUserInterfaceSizeClass)horizontalSizeClass { | |
if ([owningViewController.view respondsToSelector:@selector(traitCollection)]) { | |
return owningViewController.view.traitCollection.horizontalSizeClass; | |
} else { | |
if (([FC_Settings sharedFC_Settings].deviceType == iPad) || ([FC_Settings sharedFC_Settings].deviceType == iPadRetina)) | |
return UIUserInterfaceSizeClassRegular; | |
else return UIUserInterfaceSizeClassCompact; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment