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

移动开发 iOS
iPhone开发中为UINavigationBar设置背景图片方法是本文要介绍的内容,在iPhone开发中, 有时候我们想给导航条添加背景图片, 实现多样化的导航条效果,具体内容来看本文。

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设置背景图片方法的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2010-08-18 13:27:15

CSS兼容IE6

2010-09-09 14:38:05

CSS背景图片

2010-08-26 10:26:44

CSS

2011-09-01 15:16:00

Ubuntu

2009-03-19 08:54:15

Windows 7定制登陆界面

2010-10-13 08:57:06

Visual Stud

2010-04-27 11:35:05

Oracle Java

2011-06-03 14:04:11

Android

2020-12-16 07:29:23

Windows10操作系统动态锁屏

2011-08-08 15:48:13

iPhone TableView 背景

2010-11-23 10:51:45

UI交互设计产品管理

2010-09-07 08:54:18

CSSbackground-

2011-09-07 16:24:10

Qt Widget

2009-11-09 19:59:47

2011-03-16 11:22:16

iconDefaultiPhone

2011-08-29 17:58:19

Ubuntu

2019-03-14 08:47:49

Visual Stud数据开发

2010-09-03 14:00:29

CSSbackground

2011-06-28 16:05:12

Qt widget 图片

2011-08-08 14:07:49

iPhone开发 字体
点赞
收藏

51CTO技术栈公众号