IOS系列——导航条的多种操作
2014-03-07 17:11
274 查看
1)导航控制器的创建及导航条颜色、背景图片的设置:
2)导航条添加一个UITextField
3)导航条添加一个UIButton
无论是设置self.navigationItem.leftBarButtonItem.title =@"返回";还是self.navigationItem.backBarButtonItem.title
=@"返回";都没有效果,title文本始终不会发生变化。到网上乱搜一通后,得到了以下解决方法,相对来说比较简单
在第一级页面的viewDidLoad方法中加入以下代码:
也就是用一个新的按钮在进行导航前将原来的返回按钮替换掉就可以了。
要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是
设置导航条颜色要和背景色 左右按钮的颜色
如果有多个按钮,设置某一个按钮颜色可以使用
更多运用 在: http://blog.csdn.net/hufengvip/article/details/17193359
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; // self.window.rootViewController = self.viewController; //创建导航控制器 UINavigationController *nvc=[[[UINavigationController alloc]initWithRootViewController:vc]autorelease]; self.window.rootViewController=nvc; //修改颜色 // nvc.navigationBar.tintColor=[UIColor blueColor]; //修改NAvigationBar的背景图片 //获取背景图片 NSString *str=[[NSBundle mainBundle]pathForResource:@"navigationbar_background" ofType:@"png"]; UIImage *barImg=[[UIImage alloc]initWithContentsOfFile:str]; //设置背景图片 [nvc.navigationBar setBackgroundImage:barImg forBarMetrics:UIBarMetricsDefault]; [self.window makeKeyAndVisible]; return YES; }
2)导航条添加一个UITextField
//如果存在导航控制器,则设置导航条 if (self.navigationController) { //创建一个UITextField UITextField *txtURL=[[[UITextField alloc]initWithFrame:CGRectMake(10, 5, 200, 25)]autorelease]; //将txt改为圆角 txtURL.borderStyle=UITextBorderStyleRoundedRect; //设置字体大小 txtURL.font=[UIFont systemFontOfSize:12]; //设置提示 txtURL.placeholder=@"请输入网址"; //设置键盘的return类型为GO txtURL.returnKeyType=UIReturnKeyGo; //设置代理 txtURL.delegate=self; self.txtURL=txtURL; //创建UIBarButtonItem,添加self.txtURL UIBarButtonItem *txtURLBtn=[[[UIBarButtonItem alloc]initWithCustomView:self.txtURL]autorelease]; //设置导航条的左侧按钮 self.navigationItem.leftBarButtonItem=txtURLBtn; }
3)导航条添加一个UIButton
UIButton *cancelBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置按钮的位置 cancelBtn.frame=CGRectMake(200, 5, 80, 25); //设置按钮的title [cancelBtn setTitle:@"取消" forState:UIControlStateNormal]; UIBarButtonItem *rightBtn=[[[UIBarButtonItem alloc]initWithCustomView:cancelBtn]autorelease]; self.navigationItem.rightBarButtonItem=rightBtn;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(searchView:)];
无论是设置self.navigationItem.leftBarButtonItem.title =@"返回";还是self.navigationItem.backBarButtonItem.title
=@"返回";都没有效果,title文本始终不会发生变化。到网上乱搜一通后,得到了以下解决方法,相对来说比较简单
在第一级页面的viewDidLoad方法中加入以下代码:
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title = @"返回"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release];
也就是用一个新的按钮在进行导航前将原来的返回按钮替换掉就可以了。
要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
设置导航条颜色要和背景色 左右按钮的颜色
self.navigationController.navigationBar.barTintColor = MAINCOLOR; //导航条颜色 self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; //导航条按钮颜色 [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil]]; //导航条title文字颜色
如果有多个按钮,设置某一个按钮颜色可以使用
self.itemSave.tintColor = [UIColor blackColor];
更多运用 在: http://blog.csdn.net/hufengvip/article/details/17193359
相关文章推荐
- ios开发系列之文件的写入读取,NSUserDefaults存储数据,NSFileManager操作文件和文件夹
- ios系列——导航条整理
- iOS开发系列课程(08) --- 事件处理详解和手势操作
- iOS开发系列 ---- UI (TableView的编辑和多项删除操作)
- ios助手开发系列(四):文件操作系列1 - 获取设备文件信息 AFCFileInfoOpen函数和AFCKeyValueRead函数
- ios开发系列之Sqlite3的增删改查相关操作
- 【学习ios之路:UI系列】修改图片的尺寸大小操作
- 【学习ios之路:UI系列】获取ios系统版本的相关操作. 及 将汉字转化为拼音功能实现
- ios助手开发系列(五):文件操作系列2 - 操作文件和文件夹所需要开启的服务:AFC服务和AFC2服务
- IOS系列——键盘的简单操作
- ios开发系列之系统通讯录的相关操作
- 多种方法实现禁止文本框、文本的系列操作
- ios助手开发系列(六):文件操作系列3 - 文件上传和文件下载
- IOS系列——数据库的操作
- iOS文件(夹)快速简单完成增、删、改、查、写系列文件操作
- iOS 个人页面展示(导航条操作)
- php基础系列:从用户登录处理程序学习mysql扩展基本操作
- IOS Foundation文件操作实例分析
- Git学习系列(三)版本回退和管理文件的修改及删除操作
- IOS 10 适配 系列_0_ iOS10 UserNotifications 框架解析