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

UINavigationController(导航控制器)

2015-12-27 14:07 621 查看
UINavigationController(导航控制器)

界面可以滑动,多用于做轮播图

//修改导航视图控制器的半透明效果,默认是YES
self.navigationController.navigationBar.translucent=NO;
//修改背景颜色
self.navigationController.navigationBar.barTintColor=[UIColor orangeColor];

self.title=@"第一页";


//(1)标题
//    self.navigationItem.title=@"豆瓣电影";
//    self.title=@"天猫首页";
//两个都可以
注:self.title后面的标题也会跟着改变

//    UISegmentedControl *seg=[[UISegmentedControl alloc] initWithItems:@[@"信息",@"通话"]];
//    self.navigationItem.titleView=seg;
//    [seg release];

//可以把label放到titleView上,能修改label的内容,比如字体的大小
//    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
//    label.text=@"豆瓣电影";
//    self.navigationItem.titleView=label;
//    [label release];
//    label.font=[UIFont systemFontOfSize:25];


创建按钮

//创建左边的按钮
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(barAction:)];

//第二种方式
self.navigationItem.rightBarButtonItem=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.jpg"] style:UIBarButtonItemStylePlain target:self action:@selector(barAction:)] autorelease];

//第三种方式
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"确认" style:UIBarButtonItemStylePlain target:self action:@selector(barAction:)];

//第四种,使用自定义的视图
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
button.frame=CGRectMake(0, 0, 40, 40);
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:button];


跳转页面

//跳转按钮
UIButton *pushButton=[UIButton buttonWithType:UIButtonTypeSystem];
pushButton.frame=CGRectMake(100, 100, 150, 50);
pushButton.layer.borderWidth=1;
pushButton.layer.cornerRadius=10;
[pushButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
[pushButton setTitle:@"下一页" forState:UIControlStateNormal];
[self.view addSubview:pushButton];


点击方法
-(void)click:(UIButton *)button{
//模态跳转(复习)
//    SecondViewController *secVC=[[SecondViewController alloc] init];
//    [secVC setModalTransitionStyle:0];
//    [self presentViewController:secVC animated:YES completion:^{
//
//    }];

//通过导航视图控制器进行跳转操作
//1.创建下一页的目标对象
SecondViewController *secVC=[[SecondViewController alloc] init];
//2.跳转
[self.navigationController pushViewController:secVC animated:YES];
//3.内存管理
[secVC release];

}


从第二页跳转回来的点击方法

-(void)click:(UIButton *)button{
ThirdViewController *thirdVC=[[ThirdViewController alloc] init];
[self.navigationController pushViewController:thirdVC animated:YES];
[thirdVC release];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: