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

UI07_导航试图控制器及从前往后传值

2015-08-08 11:27 549 查看
导航视图控制器高度是44,上面的状态栏高度是20.加在一起默认是64;
item是内容bar是样式


1.加标题

第一种方法:
self.title=@"猫眼电影";
第二种方法:
self.navigationItem.title=@"猫眼电影";


2.背景颜色的设置

self.navigationController.navigationBar.barTintColor=[UIColor blueColor];


3.bar设置成不透明(防止坐标系被篡改,设置完成后原点会自动向下64)

self.nacigationController.navigationBar.trandlucent=NO;


4.titleView(在上面栏中显示其内容,并分割成信息和通话)

意思是:先用UISegmentControl分割两个部分  再将其添加到导航控制器的上栏上
UISegmentedContrl *seg=[[UISegmentedControl alloc]initWithItem:@[@"信息",@"通话"];
self.navigationItem.titleView=seg;


5.创建左右两边的按钮

在左边设置
显示的结果是加号
self.navigationItem.leftBarButtonItem=[[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItenAdd target:self action:@selector(leftButtonAction:)]autorelease];
//点击实现部分
-(void)leftButtonAction:(UIBarButtonItem *)button
{
NSLog(@"大好河山");
}

在右边设置
思路是:先创建一个button,添加上图片然后再将button添加到上边栏的右边
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
//相对应右边位置而不是相对视图
rightButton.frame=CGRectMake(0, 0, 40, 40);
[rightButton setImage:[UIImage imageNamed:@"sheshou.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];


6.跳转下一个视图.并进行属性传值

在Main视图控制器上添加second的头文件
second.h中我们设置一条属性(传值桥梁)
@property (nonatomic, copy)NSString *str;
下面这条属性用来显示传过来的内容
@property (nonatomic, assign)UILabel *label;
在.m文件中对属性进行创建和设置(别忘记内存释放)
self.label=[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 40)];
[self.view addSubview:self.label];
[self.label release];
//把属性的内容对label进行赋值    用定义的字符串
self.label.text=self.str;

创建button用于返回上一个页面
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(200, 100, 100, 40);
[button setTitle:@"返回" forState:UIControlStateNormal];
[self.view addSubview:button];
button.layer.borderWidth=1;
button.layer.cornerRadius=10;
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

点击方法的实现
-(void)click:(UIButton *)button
{
[self.navigationController popToViewController:MainViewController animated:YES];
}

在main.m中的设置

创建一个button,目的是设置点击效果
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(200, 100, 100, 40);
[button setTitle:@"下一页" forState:UIControlStateNormal];
[self.view addSubview:button];
button.layer.borderWidth=1;
button.layer.cornerRadius=10;
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

点击方法:
-(void)click:(UIButton *)button
{
//导航控制器进行跳转
//通过这个点知道当前管理者是谁   是navigationController
SecondViewController *secondVC = [[SecondViewController alloc]init];
//属性传值的第二步
secondVC.str=self.myTextField.text;
[self.navigationController pushViewController: secondVC animated:YES];
[secondVC release];

//    //模态跳转到下一页
//     SecondViewController *secondVC = [[SecondViewController alloc]init];
//    [secondVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
//    [self presentViewController:secondVC animated:YES completion:^{
//
//    }];
//    [secondVC release];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: