Skip to content

Instantly share code, notes, and snippets.

@v9n
Forked from danielphillips/DJPAppDelegate.h
Last active December 17, 2015 18:09
Show Gist options
  • Save v9n/5651511 to your computer and use it in GitHub Desktop.
Save v9n/5651511 to your computer and use it in GitHub Desktop.
@interface DJPAppDelegate : UIResponder <UIApplicationDelegate, UIAppearanceContainer>
@end
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor redColor];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
}
@end
@implementation DJPAppDelegate
// missing code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
DJPMasterViewController *masterViewController = [[[DJPMasterViewController alloc] initWithNibName:@"DJPMasterViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
if([UINavigationBar respondsToSelector:@selector(appearance)]){
UIImage *image = [UIImage imageNamed:@"bg.png"];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
return YES;
}
//Instead of creating image from existing image. we can create it dynamically
//
- (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size {
//Create a context of the appropriate size
UIGraphicsBeginImageContext(size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//Build a rect of appropriate size at origin 0,0
CGRect fillRect = CGRectMake(0,0,size.width,size.height);
//Set the fill color
CGContextSetFillColorWithColor(currentContext, color.CGColor);
//Fill the color
CGContextFillRect(currentContext, fillRect);
//Snap the picture and close the context
UIImage *retval = UIGraphicsGetImageFromCurrentImageContext(void);
UIGraphicsEndImageContext();
return retval;
}
// missing code
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment