iphone iPhone开发中为UINavigationBar设置背景图片方法

1:原文摘自:http://mobile.51cto.com/iphone-284865.htm

iPhone开发中为UINavigationBar设置背景图片方法是本文要介绍的内容,在iPhone开发中, 有时候我们想给导航条添加背景图片, 实现多样化的导航条效果, 用其他方法往往无法达到理想的效果, 经过网上搜索及多次实验, 确定如下最佳实现方案。

为UINavigatonBar增加如下Category:

 
 
  1. @implementation UINavigationBar (CustomImage)     
  2. - (void)drawRect:(CGRect)rect {     
  3.     UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];     
  4.     [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];     
  5. }     
  6. @end    

例如, 在我的项目中, 添加如下代码:

 
 
  1. /* input: The image and a tag to later identify the view */     
  2. @implementation UINavigationBar (CustomImage)     
  3. - (void)drawRect:(CGRect)rect {     
  4.     UIImage *image = [UIImage imageNamed: @"title_bg.png"];     
  5.     [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];     
  6. }     
  7. @end     
  8.  
  9. @implementation FriendsPageViewController     
  10. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.     
  11. - (void)viewDidLoad {        
  12.     self.navigationBar.tintColor = [UIColor purpleColor];     
  13.          
  14.     [self initWithRootViewController:[[RegPageViewController alloc] init]];     
  15.     [super viewDidLoad];     
  16. }    

实现的效果如下图:

iPhone开发中为UINavigationBar设置背景图片方法

小结:iPhone开发中为UINavigationBar设置背景图片方法的内容介绍完了,希望通过本文的学习能对你有所帮助!

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值