Ben*_*tto 3 iphone textures colors uitoolbar
我试过这样做:
[toolbar setTint:[UIColor colorWithPatternImage:[UIImage imageNamed:@"thingFromMyBundle.png"]]];
但它只是黑色.起初我假设你不允许用纹理"着色",但我最近看到的应用程序可以做到这一点.我错过了什么吗?
谢谢.
将2个文件添加到项目中,调用它们UINavigationBar-CustomTexture.h,UINavigationBar-CustomTexture.m例如,在这些文件中放置:
.h文件:
#import <UIKit/UIKit.h>
@interface UINavigationBar (CustomTexture)
@end
.m文件:
#import "UINavigationBar-CustomTexture.h"
@interface UIView (CustomTexture)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
@end
@implementation UINavigationBar (CustomTexture)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
    if ([self isMemberOfClass:[UINavigationBar class]]){
        UIImage *image = [UIImage imageNamed:@"myImage.png"];
        CGContextScaleCTM(ctx, 1.0f, -1.0f);
        CGContextDrawImage(ctx, CGRectMake(0, -image.size.height, self.frame.size.width, self.frame.size.height), image.CGImage);
    }else{
        [super drawLayer:layer inContext:ctx];
    }
}
@end
在实例化导航控制器的地方包含.h文件.将您的png文件设置为320x44.根据您的纹理,将导航栏的色调颜色更改为这样(使导航栏上的按钮看起来更好):
[self.navigationController.navigationBar setTintColor:[UIColor colorWithHue:0 saturation:0 brightness:0.5f alpha:0.1f]];