IOS系列——自定义导航条
来源:互联网 发布:wall control软件下载 编辑:程序博客网 时间:2024/06/03 11:17
导航条的自定义需要继承 UINavigationController
新建一个类:MyNav 继承 UINavigationController
判断系统版本
#define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
实现导航条自定义图片:在viewDidload里面添加
// 1.取出设置主题的对象 UINavigationBar *navBar = [UINavigationBar appearance]; // 2.设置导航栏的背景图片 NSString *navBarBg = nil; if (iOS7) { // iOS7 navBarBg = @"navBG"; navBar.tintColor = [UIColor whiteColor]; //IOS7版本才有,设置导航条的左按钮的颜色 } else { // 非iOS7 navBarBg = @"navBG"; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent; } [navBar setBackgroundImage:[UIImage imageNamed:navBarBg] forBarMetrics:UIBarMetricsDefault]; // 3.设置标题颜色 [navBar setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor whiteColor] }];
在页面里面
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]]; [self setTitle:@"第二个页面"]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(backBarButtonItem)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStylePlain target:self action:@selector(perFormAdd:)];//为导航栏添加右侧按钮 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(perFormAdd:)];//为导航栏左侧添加系统自定义按钮
self.title = @"页面名字"; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:nil action:nil];//下一页出来的导航条返回按钮是 返回 两个字
UISwitch *simpleSwitch = [[UISwitch alloc] init];//实例化一个选择开关 simpleSwitch.on = YES;//开关设置为开启状态 [simpleSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];//添加事件 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:simpleSwitch];//将开关控件赋给导航栏右按钮对开关添加事件
-(void)switchChanged:(UISwitch *)paramSender{ if ([paramSender isOn]) {//如果开关状态为开启 NSLog(@"Switch is on."); }else{ NSLog(@"Switch is off."); }}
0 0
- IOS系列——自定义导航条
- ios系列——导航条整理
- IOS系列——导航条UINavigationController的简单功能
- IOS系列——导航条的多种操作
- [iOS 自定义导航栏/导航条]隐藏系统导航条
- Android自定义组件系列【10】——随ViewPager滑动的导航条
- IOS系列——导航条UINavigationController的使用和不要xib文件的页面推
- IOS 5 自定义导航条背景图片
- 【代码笔记】iOS-自定义导航条颜色
- IOS开发—自定义导航控制器
- iOS源码学习-导航条加阴影,自定义导航条的背景图片
- ios5自定义导航条
- 自定义导航条1
- android 自定义导航条
- 自定义快速导航条
- IOS系列——调用第三方地图导航
- iOS开发UINavigation系列四——导航控制器UINavigationController
- 【17】Bootstrap — 导航条
- SIP开源项目opensip,Freeswitch
- Hudson标准安全设置 (权限设置)
- 一些数据库汇总
- javaScript 的小技巧
- Inventory Period Has A Status Of ''Closed Not Summarized''
- IOS系列——自定义导航条
- 范式
- 设计模式介绍之二:单例模式(Singleton)
- linux0.11中的进程
- html语义化
- StringBuilder对象Capacity属性
- 排序
- 安装gentoo的点点滴滴(一)
- lua实现的状态机