-
-
Save v9n/5651511 to your computer and use it in GitHub Desktop.
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
@interface DJPAppDelegate : UIResponder <UIApplicationDelegate, UIAppearanceContainer> | |
@end |
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
@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