视图控制器
一、UITabBarController 工具栏控制器(选项卡控制器)
UITabBar 选项卡栏
尺寸:320*49px
属性: 
图标或文字颜色 
tbBar.tabBar.tintColor = [UIColor yellowColor]; 
背景颜色 
tbBar.tabBar.barTintColor = [UIColor blackColor]; 
背景图片 
tbBar.tabBar.backgroundImage = [UIImage imageNamed:@”tab_49”];
UITabBarItem 选项卡项 
Badge 右上角标识
关系 
1.创建基本的视图控制器 
OneViewController *one = [[OneViewController alloc] init]; 
TwoViewController *two = [[TwoViewController alloc] init];
2.创建导航栏控制器 
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:one]; 
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:two];
3.创建选项卡控制器 
UITabBarController *tabBar = [[UITabBarController alloc] init]; 
tabBar.viewControllers = @[nav1,nav2];
设置选项卡项的内容 
nav1.tabBarItem.title = @”美女1”; 
nav1.tabBarItem.image = [UIImage imageNamed:@”tabbar_1”]; 
nav2.tabBarItem.title = @”美女2”; 
nav2.tabBarItem.image = [UIImage imageNamed:@”tabbar_2”];
设置导航栏项的内容 
one.navigationItem.title = @”美女1”;//标题 
two.navigationItem.title = @”美女2”;//标题
二、UINavigationController 导航栏控制器
UINavigationBar 导航栏 
尺寸: 
7.0之前 44px 
7.0以后 44+20(状态栏)px
属性: 
背景颜色 
self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
按钮颜色 
self.navigationController.navigationBar.tintColor = [UIColor greenColor]; 
背景图片 
[self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault]; 
标题样式(颜色、字体) 
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}; 
是否透明 
self.navigationController.navigationBar.translucent = flag;
创建导航栏按钮的三种方式: 
1.创建自带标题的按钮 
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@”添加” style:UIBarButtonItemStyleDone target:nil action:nil]; 
2.创建系统自带的按钮 
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil]; 
3.创建自带图片的按钮 
UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@”cc”] style:UIBarButtonItemStyleDone target:nil action:nil];
导航栏跳转 
push 导入(入栈) 
ThreeViewController *two = [[ThreeViewController alloc] init]; 
[self.navigationController pushViewController:two animated:YES];
pop 导出(出栈) 
返回上一级 
[self.navigationController popViewControllerAnimated:YES]; 
返回顶层 
[self.navigationController popToRootViewControllerAnimated:YES]; 
返回指定层 
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
隐藏返回按钮 
self.navigationItem.hidesBackButton = YES;
设置是否隐藏导航栏 
[self.navigationController setNavigationBarHidden:YES animated:YES];
加载半透明背景 
  [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:_popView];
- (void)bgImageView_method {
    // 半透明背景
    _bgImage= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, XBScreenWidth, XBScreenHeight)];
      [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:_bgImage];
    _bgImage.backgroundColor = [UIColor blackColor];
    _bgImage.alpha = 0.5;
    _popView = [[UIView alloc]init];
  [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:_popView];
    [_popView zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.centerByView(_bgImage,0);
        layout.leftSpace(10);
        layout.rightSpace(10);
        layout.heightValue(168);
    }];
    _popView.backgroundColor = [UIColor whiteColor];
    UIButton *backbtn = [[UIButton alloc] init];
    [_popView addSubview:backbtn];
    [backbtn zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpace(7);
        layout.rightSpace(8);
        layout.widthValue(21);
        layout.heightValue(21);
    }];
    [backbtn addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
    [backbtn setBackgroundImage:[UIImage imageNamed:@"close_cheat_page"] forState: UIControlStateNormal];
}
                  
                  
                  
                  
                            
本文详细介绍了iOS开发中UITabBarController选项卡控制器和UINavigationController导航栏控制器的使用方法,包括尺寸、属性设置、按钮创建及视图跳转等关键操作。
          
      
          
                
                
                
                
              
                
                
                
                
                
              
                
                
              
            
                  
					2657
					
被折叠的  条评论
		 为什么被折叠?
		 
		 
		
    
  
    
  
            


            