您的位置:首页 > 产品设计 > UI/UE

iPhone开发 自定义 uinavgationbar

2012-03-07 10:09 127 查看
谢谢lamo的提醒,这个5.0确实无效。

//添加5.0下需加入的代码

if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"check_yes.png"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setTintColor:[UIColor redColor]];
}


CustomNavgationBar.m

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect {
//颜色填充
//UIColor *color = [UIColor greenColor];
//CGContextRef context = UIGraphicsGetCurrentContext();
//CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
//CGContextFillRect(context, rect);
//self.tintColor = color;
//图片填充
UIColor *color = [UIColor colorWithRed:46.0f/255.0f green:87.0f/255.0f blue:29.0f/255.0f alpha:1.0f];
UIImage *img    = [UIImage imageNamed: @"button.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = color;

}
@end


CustomNavgationBar.h

- (void)drawRect:(CGRect)rect;


无需引用,在有navbar的地方自动会改变
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: