Return to Snippet

Revision: 53708
at December 1, 2011 12:28 by codeRefiner


Initial Code
- (void)customizeAppearance
{
    // Create resizable images
    UIImage *gradientImage44 = [[UIImage imageNamed:@"gradient_textured_44"] 
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    UIImage *gradientImage32 = [[UIImage imageNamed:@"gradient_textured_32"] 
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
 
    // Set the background image for *all* UINavigationBars
    [[UINavigationBar appearance] setBackgroundImage:gradientImage44 
        forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:gradientImage32 
        forBarMetrics:UIBarMetricsLandscapePhone];
 
    // Customize the title text for *all* UINavigationBars
    [[UINavigationBar appearance] setTitleTextAttributes:
        [NSDictionary dictionaryWithObjectsAndKeys:
            [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], 
            UITextAttributeTextColor, 
            [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], 
            UITextAttributeTextShadowColor, 
            [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
            UITextAttributeTextShadowOffset, 
            [UIFont fontWithName:@"Arial-Bold" size:0.0], 
            UITextAttributeFont, 
            nil]];
 
}

Initial URL


Initial Description
Here is a nice function you can use to implement a custom background for your UINavigation Bars

Simply make two images in photoshop: 

32 x 32 
44 x 44 

and name them whatever you want. 

put them in your iPhone project by dragging and dropping them from the desktop or another directory. 

If need be check the Copy Group Destination files in folder line to add the two image files to your project. 

Make sure you replace the two lines that create the UIImages with your image names


Copy And paste the function into your app delegate right above applicationDidFinishLaunchingWithOptions: 

then simply call 

[self customizeAppearance]; inside your app delegate and...

voila, enjoy :)

Initial Title
New iOS 5 API: Customize UINavigationBar Background Property with EASY function!!!

Initial Tags
iphone, ios

Initial Language
iPhone