UINavigationBar自定义导航栏背景…
2013-12-20 13:00
253 查看
UINavigationBar自定义导航栏背景和按钮,完美支持横屏竖屏旋转,视图控制器可以分别使用自己的导航栏 导航上的按钮背景需要做,否则看起来不那么和之又谐 Objective-c代码 //CustomNavigationBar.h @interface UINavigationBar (UINavigationBarCategory) UIImageView *backgroundView; - (void)setBackgroundImage:(UIImage*)image; - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; @end //CustomNavigationBar.m @implementation UINavigationBar (UINavigationBarCategory) -(void)setBackgroundImage:(UIImage*)image { if(image == nil) { [backgroundView removeFromSuperview]; } else { backgroundView = [[UIImageView alloc] initWithImage:image]; backgroundView.tag = 1; backgroundView.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height); backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self addSubview:backgroundView]; [self sendSubviewToBack:backgroundView]; [backgroundView release]; } } //for other views - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index { [super insertSubview:view atIndex:index]; [self sendSubviewToBack:backgroundView]; } @end //YourViewController.m - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation_bar_bg.png"]]; } |
相关文章推荐
- 导航部分选中的背景跟随鼠标滑动
- iOS 7+自定义导航栏背景,标题和返回按钮文字颜色
- js控制导航背景与字体颜色变化
- Web前端-JS效果-导航弹框、背景变色、鼠标移动切换等常见的js效果
- iOS 去掉UINavigationController(导航控制器)去除底部黑线、改背景颜色或者改为全透明
- 导航菜单背景切换效果
- 不规则背景墙 CSS实现背景图片不规则的导航菜单
- HTML导航 - 点击更改背景
- 汽车导航系统背景介绍
- iOS7 设置背景图片或导航为毛玻璃效果
- js实现的黑背景灰色二级导航菜单效果代码
- 导航加背景加特效,多而合一,绝对酷,绝对绝--全空间一个代码
- jQuery制作的别致导航有阴影背景高亮模式窗口
- ios 自定义导航栏背景图片和颜色
- Dreamweaver中实现双背景图片导航菜单的代码
- 滑动的导航,背景图片或者边框滑动效果
- 导航条——动态改变导航菜单的背景颜色
- JQuery的hover()方法使鼠标指针移过导航,改变背景颜色
- 鼠标经过切换背景的导航菜单