手机QQ底部分栏效果【标签栏】

AppDelegate.m

//
//  AppDelegate.m
//  Task5
//
//  Created by lyb on 14-9-27.
//  Copyright (c) 2014年 imac. All rights reserved.
//

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    FirstViewController *firstCtrl = [[FirstViewController alloc] init];
    SecondViewController *secondCtrl =[[SecondViewController alloc] init];
    
    UINavigationController *navCtrl1 = [[UINavigationController alloc] initWithRootViewController:firstCtrl];
    UINavigationController *navCtrl2 = [[UINavigationController alloc] initWithRootViewController:secondCtrl];
    
    UITabBarController *tabbarCtrl = [[UITabBarController alloc] init];
    tabbarCtrl.viewControllers = @[navCtrl1, navCtrl2];
    
    self.window.rootViewController = tabbarCtrl;
    
    return YES;
}


@end

FirstViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"左";
    
    self.view.backgroundColor = [UIColor redColor];
}

SecondViewController.m

#import "SecondViewController.h"
#import "ThirdViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"右";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor greenColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    button.frame = CGRectMake(90, 90, 90, 50);
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)buttonAction
{
    ThirdViewController *thirdCtrl = [[ThirdViewController alloc] init];
    
    [self.navigationController pushViewController:thirdCtrl animated:YES];
}

ThirdViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //隐藏标签栏工具栏
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor orangeColor];
    self.title = @"三";
    
}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。