开发者

Change colour Navigation Bars, Tab Bars

开发者 https://www.devze.com 2023-01-21 06:31 出处:网络
how do you c开发者_StackOverflowhange 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.

how do you c开发者_StackOverflowhange 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消