iOS入门(三十二)UINavigationController

UINavigationController   
作用:管理视图控制器
导航控制器继承于UIViewController,以栈的方式管理所控制的视图控制器   创建的时候需要用户提供一个视图控制器作为导航控制器的一个根视图控制器

    pushViewController:animated //进入下一个视图控制器

    popViewControllerAnimated //返回上一个视图控制器

    popToViewController:animated //返回到指定的视图控制器

    popToRootViewControllerAnimated //返回到根视图控制器


定制UINavigationBar

ois7默认的navigationBar 高度是64

如果将navigationBar的透明度关闭,navigationBar的高度将会变为44

 

  修改UINavigationBar的背景图片,背景颜色 UINavigationItem的使用

传值(第二个视图控制器获得第一个视图控制器的部分信息:

属性传值

单例传值(类只有一个实例,也是一种常用的设计模式)

代理传值




 

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    //设置导航栏不透明

    [self.navigationController.navigationBar setTranslucent:NO];

    self.title @"标题";

//    //设置导航栏样式

//    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];

//    //设置导航栏颜色

//    [self.navigationController.navigationBar setBarTintColor:[UIColor orangeColor]];

//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.bmp"] forBarMetrics:UIBarMetricsDefault];

    //设定导航栏上的视图back  只会取其样式 不去我设的功能

    //    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"你猜" style: UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];

    

    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithTitle:@"AAA" style:UIBarButtonItemStylePlaitarget: self action:@selector(buttonClicked:)],[[UIBarButtonItem alloc] initWithTitle:@"AAA" style:UIBarButtonItemStylePlaitarget: self action:@selector(buttonClicked:)], nil];

    

    UIButton * label = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];

    label.backgroundColor = [UIColor cyanColor];

    [label addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

    //titleView本身是一个空指针,必须设置个东西给它,让这个指针去指向它

    NSLog(@"%@",self.navigationItem.titleView);

    self.navigationItem.titleView = label;

    [label release];

    

    

    

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame CGRectMake(20, 20, 200, 150);

    button.backgroundColor = [UIColor greenColor];

    [button setTitle:@"嘻嘻,我是按钮" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

    

    

    

    

    

    

}


- (void)buttonClicked:(UIButton *)button

{

    //2.创建一个要入栈的视图控制器

    SecondViewController *secondController = [[SecondViewController alloc] init];

    //3.获得当前的navigationController,利用它推出新的视图控制器

    [self.navigationController pushViewController:secondController animated:YES];

    [secondController release];

    

}

 



 

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor colorWithRed:0.3 green:0.1 blue:0.6 alpha:0.6];

    [self.navigationController.navigationBar setTranslucent:NO];

    self.title @"四大美女";

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"BBB" style:UIBarButtonItemStylePlaitarget:self action:@selector(buttonClicked:)];

//    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];

//    button.frame = CGRectMake(50, 150, 200, 150);

//    button.backgroundColor = [UIColor yellowColor];

//    [button setTitle:@"我也是按钮" forState:UIControlStateNormal];

//    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

//    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

//    [self.view addSubview:button];

    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 250, 100)];

    label.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:label];

    [label release];

}


- (void)buttonClicked:(UIButton *)button

{

    ThirdViewController * thirdController = [[ThirdViewController alloc] init];

    [self.navigationController pushViewController:thirdController animated:YES];

    [thirdController release];


}

 



 

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    [self.navigationController.navigationBar setTranslucent:NO];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"DDD" style:UIBarButtonItemStylePlaitarget:self action:@selector(buttonClicked:)];

    self.view.backgroundColor = [UIColor grayColor];

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame CGRectMake(50, 150, 200, 150);

    button.backgroundColor = [UIColor blackColor];

    [button setTitle:@"按钮。。按钮" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];


}


- (void)buttonClicked:(UIButton *)button

{

    //返回到根视图控制器

//    [self.navigationController popToRootViewControllerAnimated:YES];

    //返回上一个视图控制器

//    [self.navigationController popViewControllerAnimated:YES];

    //返回到栈内的某一个视图

//    UIViewController * vc = [self.navigationController.viewControllers objectAtIndex:1];

//    [self.navigationController popToViewController: vc animated:YES];

    FiveViewController * fiveController = [[FiveViewController alloc] init];

    [self.navigationController pushViewController:fiveController animated:YES];

    [fiveController release];

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值