利用objective-c的Category语法 扩展UINavigationBar 类
具体代码为
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
// Drawing code
UIImage *img = [UIImage imageNamed: @"navbar_background.png"];
CGPoint point = {0,0};
[img drawAtPoint:point];
}
@end
方法2
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
//加入旋转坐标系代码
// Drawing code
UIImage *navBarImage = [UIImage imageNamed:@"LOGO_320×44.png"];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, self.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGPoint center=self.center;
CGImageRef cgImage= CGImageCreateWithImageInRect(navBarImage.CGImage,CGRectMake(0, 0, 1, 44));
CGContextDrawImage(context, CGRectMake(center.x-160-80, 0, 80,self.frame.size.height), cgImage);
CGContextDrawImage(context, CGRectMake(center.x-160, 0, 320,self.frame.size.height), navBarImage.CGImage);
CGContextDrawImage(context, CGRectMake(center.x+160, 0, 80,self.frame.size.height), cgImage);
}
@end
old code
CGContextDrawImage(context, CGRectMake(0, 0, self.frame.size.width,self.frame.size.height), navBarImage.CGImage);