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

UI_标签导航控制器

2016-01-23 14:52 681 查看
#import "AppDelegate.h"
//#import "RootViewController.h"
//#import "OneViewController.h"
//#import "TwoViewController.h"
#import "RootTabBarController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    /*
    RootViewController *rootVC = [[RootViewController alloc]init];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:rootVC];

    

    
    OneViewController *oneVC = [OneViewController new];
    UINavigationController *naVC1 = [[UINavigationController alloc]initWithRootViewController:oneVC];

    
    TwoViewController *twoVC = [TwoViewController new];
    UINavigationController *naVC2 = [[UINavigationController alloc]initWithRootViewController:twoVC];

  

//tabBarController的使用
        //初始化
    UITabBarController *myTabBarController = [UITabBarController new];
        //将创建好的导航控制器放入tabBarController中
        //为tabBarController添加子视图控制器
    myTabBarController.viewControllers = @[naVC,naVC1,naVC2];
        //设置底部的item
    naVC.tabBarItem.title = @"卧";
        //设置图片,去掉图片渲染
    naVC.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //设置tabBarItem的颜色
    myTabBarController.tabBar.tintColor = [UIColor redColor];
        //设置tabBar的颜色
    myTabBarController.tabBar.barTintColor = [UIColor yellowColor];
        //设置item的角标
    naVC.tabBarItem.badgeValue = @"10";

        //设置默认被选中的item(切换界面就是依靠此属性的改变,默认值为0)
    myTabBarController.selectedIndex = 0;
    //myTabBarController.selectedViewController = naVC1;   
等同上句

   

    
    //添加第二个
    naVC1.tabBarItem.title = @"操";
    naVC1.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    

    
    //添加第三个
    naVC2.tabBarItem.title = @"哦";
    naVC2.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    

    

    
        //将tabBarController设置为window的根视图控制器
    self.window.rootViewController = myTabBarController;
  */

 
    RootTabBarController *rootTabBarController = [RootTabBarController new];
    self.window.rootViewController = rootTabBarController;

    

    

    

    

    

    

    

    

    

    

    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}@end

#import "RootTabBarController.h"
#import "RootViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
#import "FourViewController.h"
#import "FiveViewController.h"
#import "SixViewController.h"
@interface RootTabBarController ()

@end

@implementation RootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

//第一个
//    RootViewController *rootVC = [RootViewController new];
//    UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:rootVC];
//    
//    navC.tabBarItem.title = @"一";
//    navC.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    navC.tabBarItem.badgeValue = @"1";

//第一个
    OneViewController *oneVC = [OneViewController new];
    UINavigationController *one = [[UINavigationController alloc]initWithRootViewController:oneVC];

    
   // one.tabBarItem.title = @"一";
   // one.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    
        //系统的图标风格
    one.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1001];
    one.tabBarItem.badgeValue = @"1";

//第二个
    TwoViewController *twoVC = [TwoViewController new];
    UINavigationController *two = [[UINavigationController alloc]initWithRootViewController:twoVC];

    
   // two.tabBarItem.title = @"二";
   // two.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    two.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1002];
    two.tabBarItem.badgeValue = @"2";

    

    

//第三个
    ThreeViewController *threeVC = [ThreeViewController new];
    UINavigationController *three = [[UINavigationController alloc]initWithRootViewController:threeVC];

    
    //three.tabBarItem.title = @"三";
    //three.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    three.tabBarItem.badgeValue = @"3";

    
    UIImage *image1 = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *image2 = [[UIImage imageNamed:@"Two30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    
    three.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"三" image:image1 selectedImage:image2];

    

    

//第四个
    FourViewController *fourVC = [FourViewController new];
    UINavigationController *four = [[UINavigationController alloc]initWithRootViewController:fourVC];

    
    four.tabBarItem.title = @"四";
    four.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    four.tabBarItem.badgeValue = @"4";

//第五个
    FiveViewController *fiveVC = [FiveViewController new];
    UINavigationController *five = [[UINavigationController alloc]initWithRootViewController:fiveVC];

    
    //five.tabBarItem.title = @"五";
    //five.tabBarItem.image = [[UIImage imageNamed:@"han30.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    five.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"五" image:image1 tag:1005];
    five.tabBarItem.badgeValue = @"5";

    
 //第六个
    SixViewController *sixVC = [SixViewController new];
    UINavigationController *six = [[UINavigationController alloc]initWithRootViewController:sixVC];
    six.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"六" image:image1 tag:1006];
    six.tabBarItem.badgeValue = @"6";

    

    

    

    

    

    

    
        //将标签加入到控制器中
    self.viewControllers = @[one,two,three,four,five,six];
        //设置标签字体颜色
    self.tabBar.tintColor = [UIColor redColor];

        //设置标签视图控制器的颜色
    self.tabBar.barTintColor = [UIColor yellowColor];
        //设置默认显示第几个
    self.selectedIndex = 2;
        //设置是否半透明
    self.tabBar.translucent = YES;

    

    

    

    

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: