iPhone为UINavigationBar设置背景图片的方法
2010-06-19 18:36:00 来源:WEB开发网在iPhone开发中, 有时候我们想给导航条添加背景图片, 实现多样化的导航条效果, 用其他方法往往无法达到理想的效果, 经过网上搜索及多次实验, 确定如下最佳实现方案:
为UINavigatonBar增加如下Category:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
@implementation
UINavigationBar (CustomImage) - (void)drawRect:(CGRect)rect { UIImage
*image = [UIImage imageNamed: @"NavigationBar.png"]; [image
drawInRect:CGRectMake(0, 0, self.frame.size.width,
self.frame.size.height)]; } @end
例如, 在我的项目中, 添加如下代码:
/////////////////////////////////////////////////////////
/* input: The image and a tag to later identify the view */
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"title_bg.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
/////////////////////////////////////////////////////////
@implementation FriendsPageViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.navigationBar.tintColor = [UIColor purpleColor];
[self initWithRootViewController:[[RegPageViewController alloc] init]];
[super viewDidLoad];
}
......
/////////////////////////////////////////////////////////
/* input: The image and a tag to later identify the view */
@implementation UINavigationBar (CustomImage) -
(void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed:
Tags:iPhone UINavigationBar 设置
编辑录入:coldstar [复制链接] [打 印]- ››设置ScrollView滚动条的颜色
- ››iPhone应用帮助残障儿童看图说话
- ››iPhone实用工具AppBox Pro使用教程大揭秘
- ››iphone4省电方法
- ››设置的系统还原点不起作用的若干原因
- ››iphone 获取地址的详细信息
- ››iPhone 库的基本内存管理策略
- ››iPhone加密文字亲手做 私密信息有保障
- ››iphone 根据经纬度坐标取详细地址(包括国,省,市...
- ››iphone/ipad ios cocoa object-c 近期苹果UI部分小...
- ››iphone中如何进行多线程编程
- ››iPhone OS SDK的这些事[安装、下载、版本、实例、...
更多精彩
赞助商链接