Добавьте 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]];