views:

28

answers:

1

how do you change the colour of the Navigation Bars, Tab Bars?

Everytime I change it, I dont get the colour I want, It either gradient red, or gradient white/silver.

But unable to do it, default gradient blue and grey both look good but try changing it any other colour and it looks terrible.

Any tips? how to do gradient?

A: 

For Navigation Bar you could use:

[navigationController.navigationBar setTintColor:[UIColor redColor]; //Red as an example.

This would tint the color of the Navigation Bar and all it's Buttons to a specific color, in this case red. This property can also be set in Interface Builder.

And if you wanted to customize it further, you can set the background of the UINavigationBar to an image by sub-classing it. Like so…

Header File.

#import <UIKit/UIKit.h>

@interface UINavigationBar (CustomImage)

@end

Implementaion File.

#import "CustomNavigationBar.h"

@implementation UINavigationBar (CustomImage)

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx

{
    if([self isMemberOfClass: [UINavigationBar class]]){
        UIImage *image = [UIImage imageNamed:@"bar.png"];
        CGContextClip(ctx);
        CGContextTranslateCTM(ctx, 0, image.size.height);
        CGContextScaleCTM(ctx, 1.0, -1.0);
        CGContextDrawImage(ctx, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
    }else{
        [super drawLayer:layer inContext:ctx];
    }

}

@end

Then in Interface Builder set the class of you UINavigationBar to (in this case) CustomNavigationBar under the Identity Tab.

If you change the code slightly so it subclasses UITabBar instead, it might work with UITabBar although I haven't tried it.

Joshua
so complicated? :(
K001
well setting the tint color isn't but setting a completely different image is complicated.
Joshua