美文网首页
UINavigationController

UINavigationController

作者: 9bf19a4010ab | 来源:发表于2016-07-21 20:48 被阅读18次

    UINavigationController (导航控制器)

    1. 常用的视图控制器
    2. 以栈的形式管理视图控制器 先进后出
    3. 创建Navigation 会出现导航栏 (导航栏44 + 状态栏20 = 64)
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    ViewController *vc = [[ViewController alloc] init];
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = navigation;
    return YES;
    
    
    // 1. 以下两种方法都能设置viewController的标题
    self.title = @"sure";
    self.navigationItem.title = @"cancel";
    // 2. 标题视图 (修改x y对视图本身没有影响)
    UISegmentedControl *segment =     [[UISegmentedControl alloc] initWithItems:@[@"难受",   @"难受的要死"]];
    segment.frame = CGRectMake(0, 0, 150, 44);
    self.navigationItem.titleView = segment;
    // 3. 设置导航栏左右侧的按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"难受" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    // 4. 同时在导航栏创建多个button
    UIBarButtonItem *barButton1 = [[UIBarButtonItem   alloc] initWithTitle:@"难受" style:UIBarButtonItemStylePlain target:self     action:@selector(back:)];
    UIBarButtonItem *barButton2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    self.navigationItem.leftBarButtonItems =   @[barButton1, barButton2];
    // 5. navigationBar的隐藏
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden =   NO;
    // 6. barStyle
    self.navigationController.navigationBar.barStyle = 0;
    // 7. 背景颜色
    // self.navigationController.navigationBar.backgroundColor = [UIColor cyanColor];
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    // 8. 导航栏元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    // 9. 设置为半透明
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blackColor];
    button.frame = CGRectMake(0, 0, 200, 200);
    [button setTitle:@"难受死我了" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    // 10. 当设置非半透明时 button的坐标向下平移64
    self.navigationController.navigationBar.translucent = NO;
    // self.edgesForExtendedLayout = UIRectEdgeNone; // 与translucent为no时的效果一样
    
    // push和pop来完成页面之间的跳转
    
    SecViewController *sec = [[SecViewController alloc] init];
    [self.navigationController pushViewController:sec animated:YES];
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    

    相关文章

      网友评论

          本文标题:UINavigationController

          本文链接:https://www.haomeiwen.com/subject/vbgbjttx.html