IOS5修改UIToolBar 和UINavigationBar 的背景颜色
2011-11-22 21:32
549 查看
UIToolBar 三种办法
方法一
/toolBar background image set based on iOS version
[[UIDevice currentDevice] systemVersion];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"];
if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0];
}
} else {
//iOS 4
[toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0];
}
方法二
// MyToolBar.h
#import <UIKit/UIKit.h>
@interface MyToolBar : UIToolbar {
}
@end
// MyToolBar.m
#import "MyToolBar.h"
@implementation MyToolBar
- (void)drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
UIImage *image = [UIImage imageNamed:@"fish.png"];
CGContextDrawImage(c, rect, image.CGImage);
}
@end
方法三
-(void)drawRect:(CGRect)rect
{
UIImage *img = [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ToolbarBk" ofType:@"png"]] autorelease];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
UINavigationBar
在APPDelegate添加
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed:@"navbar.png"];
[img drawInRect:rect];
}@end
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
}
方法一
/toolBar background image set based on iOS version
[[UIDevice currentDevice] systemVersion];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"];
if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0];
}
} else {
//iOS 4
[toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0];
}
方法二
// MyToolBar.h
#import <UIKit/UIKit.h>
@interface MyToolBar : UIToolbar {
}
@end
// MyToolBar.m
#import "MyToolBar.h"
@implementation MyToolBar
- (void)drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
UIImage *image = [UIImage imageNamed:@"fish.png"];
CGContextDrawImage(c, rect, image.CGImage);
}
@end
方法三
-(void)drawRect:(CGRect)rect
{
UIImage *img = [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ToolbarBk" ofType:@"png"]] autorelease];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
UINavigationBar
在APPDelegate添加
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed:@"navbar.png"];
[img drawInRect:rect];
}@end
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
}
相关文章推荐
- IOS5修改UIToolBar 和UINavigationBar 的背景颜色
- IOS5修改UIToolBar 和UINavigationBar 的背景颜色
- 修改UINavigationController,UINavigationBar背景颜色,字体颜色
- UINavigationBar修改背景颜色(2)
- iOS基础:修改UINavigationController,UINavigationBar背景颜色,字体颜色
- ExtJS4.1.1 设置表格背景颜色 修改文本颜色 在表格中插入图片
- 修改手机状态栏背景颜色
- easyui框架 实现单个单元格修改背景颜色
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- UIToolBar,UINavigationBar 修改背景色
- 修改UISearchBar背景颜色
- Bootstrap navbar 背景颜色、背景图和字体颜色修改 ArcGIS Web 开发学习(四)
- Eclipse背景颜色修改
- MFC修改button的颜色、背景、边框、对话框标题
- 修改iOS导航栏标题的字体颜色和大小以及导航栏的背景图片
- 设置状态栏、导航栏背景颜色,修改导航栏返回按钮颜色
- SystemUI底部三个虚拟按键的背景颜色修改
- Eclipse背景颜色修改
- 通过C语言程序修改控制台的背景和前景颜色
- echarts的showLoading遮罩层背景颜色修改