您的位置:首页 > 产品设计 > UI/UE

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 一起使用,敬请期待
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: