UINavicationController基本应用
2016-02-19 11:47
399 查看
UINavicationController 导航栏,顾名思义为视图与视图之间切换的桥梁,简单来说,就是用来控制视图之间的跳转
请看以下代码分析:
// 设置navigationbar的半透明效果
self.navigationController.navigationBar.translucent
= NO;
[self.navigationController.navigationBar setTranslucent:NO];
//
设置navigationbar上显示的标题
self.title = @"navigationcontroller";
//
设置navigationbar的颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];
//
设置navigationbar左边按钮
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:Nil];
//
设置navigationbar右边按钮
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:Nil];
// 也可以自定义navigationbar 左右的按钮
思路:新建按钮控件rightbtn,然后 initWith rightbtn 得到UIBarButtonItem,最后赋值给rightBarButtonItem
//
设置navigationbar上左右按钮字体颜色
[self.navigationController.navigationBar setTintColor:[UIColor blueColor]];
设置导航条里面分段效果
//
设置navigation上的titleview
NSArray *arr = [NSArray arrayWithObjects:@"左边",@"右边", nil nil];
UISegmentedControl *segment = [[UISegmentedControl alloc]
initWithItems:arr];
segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
//
添加点击事件
[segmentedController addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
UISegmentedControl 分段控制,这个分段可以分为两个视图来控制,添加点击事件,根据index判断哪个分段被点击,执行相应的操作。
-(IBAction)segmentClick:(id)sender
{
switch ([sender selectedSegmentIndex]) {
case 0:
{
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了左边" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
//
执行相应的操作
}
break;
case 1:
{
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了右边" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
//
执行相应的操作
}
break;
default:
break;
}
}
如何结合UITabbarController 一起使用,敬请期待
请看以下代码分析:
// 设置navigationbar的半透明效果
self.navigationController.navigationBar.translucent
= NO;
[self.navigationController.navigationBar setTranslucent:NO];
//
设置navigationbar上显示的标题
self.title = @"navigationcontroller";
//
设置navigationbar的颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];
//
设置navigationbar左边按钮
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:Nil];
//
设置navigationbar右边按钮
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:Nil];
// 也可以自定义navigationbar 左右的按钮
思路:新建按钮控件rightbtn,然后 initWith rightbtn 得到UIBarButtonItem,最后赋值给rightBarButtonItem
//
设置navigationbar上左右按钮字体颜色
[self.navigationController.navigationBar setTintColor:[UIColor blueColor]];
设置导航条里面分段效果
//
设置navigation上的titleview
NSArray *arr = [NSArray arrayWithObjects:@"左边",@"右边", nil nil];
UISegmentedControl *segment = [[UISegmentedControl alloc]
initWithItems:arr];
segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
//
添加点击事件
[segmentedController addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
UISegmentedControl 分段控制,这个分段可以分为两个视图来控制,添加点击事件,根据index判断哪个分段被点击,执行相应的操作。
-(IBAction)segmentClick:(id)sender
{
switch ([sender selectedSegmentIndex]) {
case 0:
{
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了左边" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
//
执行相应的操作
}
break;
case 1:
{
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了右边" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
//
执行相应的操作
}
break;
default:
break;
}
}
如何结合UITabbarController 一起使用,敬请期待
相关文章推荐
- 解决UITableView中Cell重用机制问题
- mysql 报Packet for query is too large 的解决方法
- [转] sql_id VS hash_value
- angular在IE7下兼容$sce:iequirks
- iOS_UITableView性能优化那些事
- jqtransform.jsのonchangeの仕方、valueの変え方
- iOS开发UI篇—核心动画(UIView封装动画)
- iOS UIDocumentInteractionController 设置第三方打开方式的 参数详解
- Vue + webpack 项目实践
- UISearchController的简单实用
- UIDocumentInteractionController 第三方应用中打开自己的文件 方法
- Java Map 按key排序和按Value排序
- UiAutomator2自动化测试环境搭建
- Android学习路线(二十)运用Fragment构建动态UI
- 基于MVC4+EasyUI的Web开发框架形成之旅--界面控件的使用
- 关于EasyUI Datagrid JSON对象内嵌对象的取值问题
- android 键盘弹起 UI上移
- java.lang.ClassNotFoundException: filter.FiltrateRequestParamterFilter
- UITableView拉伸效果
- Android SDK Tools Platform-tools Build-tools