UINavigationBar/UITabBar 背景Hack

| 1 Comment | No TrackBacks

LOGO_320×44.png 图片显示在背景上,

@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);

hack 过logo 不再拉伸
nav_bar.png


@implementation UITabBar(Draw)


- (void)drawRect:(CGRect)rect {

    // Drawing code.

CGRect bounds=[self bounds];

NSLog(@"%@",[NSValue valueWithCGRect:bounds]);

[[UIColor redColor] set];

UIRectFill (bounds);

}

@end


tabbar.png

navbar.png

toolbar_tabbar.png

No TrackBacks

TrackBack URL: http://iphone.ipsw.info/mt/mt-tb.cgi/307

1 Comment

具体怎么使用,能说说嘛,最好给个demo事例,谢谢。

qq:37079765

Leave a comment