TabBarController


TabBar是控制 控制器的控制器. 跟navigation类似.

在AppDelegate中创建TabBar对象

#import "AppDelegate.h"

#import "FirstViewController.h"

#import "SecondViewController.h"

#import "ThirdViewController.h"

#import "FouthViewController.h"

#import "FifthViewController.h"

#import "SisthViewController.h"

@implementation AppDelegate


- (void)dealloc

{

    [_window release];

    [super dealloc];

}


@synthesize managedObjectContext = _managedObjectContext;

@synthesize managedObjectModel = _managedObjectModel;

@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    FirstViewController *first = [[[FirstViewController alloc] init]autorelease];

    SecondViewController *secton = [[[SecondViewController alloc] init] autorelease];

    ThirdViewController *third = [[[ThirdViewController alloc] init] autorelease];

    FouthViewController *fouth = [[[FouthViewController alloc] init] autorelease];

    FifthViewController *fifth = [[[FifthViewController alloc] init] autorelease];

    SisthViewController *sixth = [[[SisthViewController alloc] init] autorelease];

    NSArray *array = [NSArray arrayWithObjects:first,secton,third,fouth,fifth,sixth, nil];

    

    UITabBarController *tabBar = [[[UITabBarController alloc] init] autorelease];

    tabBar.viewControllers = array;

    tabBar.tabBar.tintColor = [UIColor greenColor];

    tabBar.delegate = self;

    self.window.rootViewController = tabBar;

    

    return YES;

}


// 以下是代理方法

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0)

{

    NSLog(@"Bool");

    return YES;

}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{

    NSLog(@"didSeclect");

}


- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers NS_AVAILABLE_IOS(3_0)

{

    

    NSLog(@"1");

}

- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed NS_AVAILABLE_IOS(3_0)

{

    NSLog(@"2");

}

- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed

{

    NSLog(@"3");

}


- (NSUInteger)tabBarControllerSupportedInterfaceOrientations:(UITabBarController *)tabBarController NS_AVAILABLE_IOS(7_0)

{

    NSLog(@"4");

    return UIInterfaceOrientationMaskAll;

}

- (UIInterfaceOrientation)tabBarControllerPreferredInterfaceOrientationForPresentation:(UITabBarController *)tabBarController NS_AVAILABLE_IOS(7_0)

{

    NSLog(@"5");

    return   UIInterfaceOrientationPortrait;

}



在第一个试图控制器中设置它的TabBar. (tabBar上的内容有三部分: 图片,文字,标记数字 )

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        

        UIImage *image = [UIImage imageNamed:@"searchSelected@2x.png"];

        self.tabBarItem.image = image;      // 图片

        self.tabBarItem.title = @"第一张";   // 文字

        self.tabBarItem.badgeValue = @"1";  // 徽章个数

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor randomColor];

    

// Do any additional setup after loading the view.

}




- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    


}






  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值