码迷,mamicode.com
首页 > 其他好文 > 详细

TabBarController-demo

时间:2015-06-18 13:15:34      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

//
//  firstViewController.m
//  TabBarcontroller
//
//  Created by 520 on 15-6-17.
//  Copyright (c) 2015年 520. All rights reserved.
//

#import "firstViewController.h"
#import "SubViewController.h"
@interface firstViewController ()

@end

@implementation firstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
//        self.title=@"First";
//        self.navigationController.navigationBarHidden=NO;
//        self.tabBarItem.badgeValue=@"1";
//        self.tabBarItem.image=[UIImage imageNamed:@"1.png"];
        
        //self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"1.png"] tag:1];
////创建tabBarItem UIImage *im =[UIImage imageNamed:@"1.png"]; self.tabBarItem.badgeValue=@"37+"; self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:im tag:1]; //self.tabBarController.tabBar.selectedImageTintColor = [UIColor orangeColor]; // [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; // [self.view addSubview:im]; // // self.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1]; // self.tabBarController.tabBar.selectedItem.selectedImage = [UIImage imageNamed:@"1.png"]; // UITabBarItem *t =[[UITabBarItem alloc] initWithTitle:@"first" image:im tag:1]; // self.tabBarItem=t; // self.tabBarItem.image=im } return self; } - (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage{ } - (void)viewDidLoad { [super viewDidLoad];
////每个页面 UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds]; imageview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;///自适应比例 imageview.image=[UIImage imageNamed:@"011.png"]; [self.view addSubview:imageview]; ////navigationcontroller UIBarButtonItem *rightBaritem=[[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)]; self.navigationItem.rightBarButtonItem=rightBaritem; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)next:(UIBarButtonItem *)barItem{ SubViewController *controller=[[SubViewController alloc] init]; [self.navigationController pushViewController:controller animated:YES]; }
#pargma mark-点击隐藏tabbaritem //// - (void)viewWillAppear:(BOOL)animated{ //[self viewWillAppear:YES]; self.hidesBottomBarWhenPushed=YES; } - (void)viewWillDisappear:(BOOL)animated{ self.hidesBottomBarWhenPushed=NO; } - (void)viewDidDisappear:(BOOL)animated{ //[self viewDidDisappear:YES]; self.hidesBottomBarWhenPushed=NO; } /* #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

技术分享
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    firstViewController *firstviewcontroller=[[firstViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    
    secondViewController *secondviewcontroller=[[secondViewController alloc] init];
    //UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    thirdViewController *thirdviewcontroller=[[thirdViewController alloc] init];
    //UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    fourViewController *fourviewcontroller=[[fourViewController alloc] init];
   // UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    
    NSArray *viewcontrollers=[[NSArray alloc] initWithObjects:nav,secondviewcontroller,thirdviewcontroller,fourviewcontroller, nil];
    UITabBarController *tabBarcontroller = [[UITabBarController alloc] init];
    tabBarcontroller.viewControllers=viewcontrollers;
    tabBarcontroller.selectedIndex=0;
    tabBarcontroller.delegate=self;
        self.window.rootViewController=tabBarcontroller;
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

  

 
 
技术分享
 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"Second" image:[UIImage imageNamed:@"2.png"] tag:2];
        
       // self.tabBarItem.badgeValue=@"37+";

        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;///自适应比例
    imageview.image=[UIImage imageNamed:@"010.png"];
    [self.view addSubview:imageview];

    // Do any additional setup after loading the view.
}

  

 
技术分享
 
 
 
技术分享

#pragma mark-响应navigationcontroller

    UIBarButtonItem *rightBaritem=[[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)];

    self.navigationItem.rightBarButtonItem=rightBaritem;

    

  

TabBarController-demo

标签:

原文地址:http://www.cnblogs.com/deng37s/p/4585557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!