UINavigationController(导航控制器)

来源:互联网 发布:qt初学者 知乎 编辑:程序博客网 时间:2024/05/23 13:08

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];}
0 0
原创粉丝点击