iPhone开发 自定义 uinavgationbar
2012-03-07 10:09
127 查看
谢谢lamo的提醒,这个5.0确实无效。
//添加5.0下需加入的代码
CustomNavgationBar.m
CustomNavgationBar.h
无需引用,在有navbar的地方自动会改变
//添加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的地方自动会改变
相关文章推荐
- iPhone开发【十八】自定义视图之ActionSheet中使用PickerView
- iphone游戏开发中使用自定义字体的方法
- iPhone地图应用开发以及自定义Annotation
- iPhone开发笔记 退回输入键盘:自定义颜色:隐藏状态栏:
- (4) iphone 开发 自定义UITableViewCell的子类 ,轻松添加图片文本信息等
- Iphone开发(十二)通过xib文件自定义列表中的行
- iphone开发笔记(-) 退回输入键盘:自定义颜色:隐藏状态栏:
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- iPhone多线程开发之线程队列NSOperationQueue与自定义Protocol
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- iPhone控件自定义控件开发:重绘还是组合 推荐
- [ios]iPhone地图应用开发以及自定义Annotation [转]
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- (1) iphone开发,自定义Window-based Application 模板及委托运行机制
- iPhone开发中自定义图标或图片的设计准则
- iphone开发自定义UIControl对象的视图 UISwitch的字体和颜色
- iPhone控件自定义控件开发:重绘还是组合
- iPhone开发学习笔记006—— NSNotification自定义通知名
- iPhone基础开发之自定义Button
- iPhone开发——通过代码自定义cell实现qq聊天界面