Skip to content

Instantly share code, notes, and snippets.

@sr75
Last active December 13, 2015 17:09
Show Gist options
  • Save sr75/4945884 to your computer and use it in GitHub Desktop.
Save sr75/4945884 to your computer and use it in GitHub Desktop.
Load nib/xib for iphone 5 / Retina 4 Full Screen (568h) custom views, but then default back to ios universal naming conventions (~iphone/~ipad).
#import "UIViewController+AppCategories.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
nibNameOrNil = [UIViewController nibNamedForDevice:@"ExampleViewController"];
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Do any additional customization
}
return self;
}
#import <UIKit/UIKit.h>
@interface UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name;
@end
// ExampleViewController.xib [iphone default when nib named empty for Retina 3.5 Full Screen]
// ExampleViewController-568h.xib [iphone custom naming convention when nib named empty for Retina 4 Full Screen (568h)]
// ExampleViewController~ipad.xib [ipad/ipad mini default when nib named empty]
#import "UIViewController+AppCategories.h"
@implementation UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if ([UIScreen mainScreen].bounds.size.height == 568)
{
//Check if there a path extension or not
if (name.pathExtension.length) {
name = [name stringByReplacingOccurrencesOfString: [NSString stringWithFormat:@".%@", name.pathExtension]
withString: [NSString stringWithFormat:@"-568h.%@", name.pathExtension ] ];
} else {
name = [name stringByAppendingString:@"-568h"];
}
// if 568h nib is found
NSString *nibExists = [[NSBundle mainBundle] pathForResource:name ofType:@"nib"];
if (nibExists) {
return name;
}
}
}
// just default to ios naming convention
return Nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment