你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS7技巧 >> IOS學習筆記UITabBarController使用教程

IOS學習筆記UITabBarController使用教程

編輯:IOS7技巧
本文章來給大家介紹ios開發中UITabBarController使用教程,希望此教程對各位會帶來幫助哦。

實現一個簡單的UITabBar:

AppDelegate.m

 代碼如下 復制代碼

- (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];
    
    
    
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(320/2-140/2, 80, 140, 40)];
    lab.text = @"王振";
    lab.textAlignment = UITextAlignmentCenter;
    lab.backgroundColor = [UIColor blueColor];
    [self.window addSubview:lab];
    
    //your code
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(320/2-140/2,480/2-40/2, 140, 40)];
    label.text = @"Hello World";
    label.backgroundColor = [UIColor cyanColor];
    label.textAlignment = UITextAlignmentCenter;
    [self.window addSubview:label];
    
    HomeViewController *view1 = [[HomeViewController alloc]init];
    UINavigationController *v1 = [[UINavigationController alloc]initWithRootViewController:view1];
 
    
    MessageViewController *view2 = [[MessageViewController alloc]init];
    UINavigationController *v2 = [[UINavigationController alloc]initWithRootViewController:view2];
    
    SearchViewController *view3 = [[SearchViewController alloc]init];
    UINavigationController *v3 = [[UINavigationController alloc]initWithRootViewController:view3];
    
    SettingViewController *view4 = [[SettingViewController alloc]init];
    UINavigationController *v4 = [[UINavigationController alloc]initWithRootViewController:view4];
    
    
    //NSArray *arr = @[view1,view2,view3,view4];
    
    NSArray *viewControllers = [NSArray arrayWithObjects:v1,v2,v3,v4 , nil];
 
    
    UITabBarController *mainViewController = [[UITabBarController alloc]init];
    mainViewController.viewControllers = viewControllers;
    //[mainViewController setViewControllers:mainViewController];
    
    //[mainViewController release];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 2;
    
    [self.window setRootViewController:mainViewController];
    
    
    return YES;
}

HomeViewController.m

 代碼如下 復制代碼 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"首頁";
        self.tabBarItem.badgeValue = @"New";
 
    }
    return self;
}
 
-(void)loadView
{
    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    view.backgroundColor = [UIColor whiteColor];
    self.view = view;
 
}

技巧:
給Iphone圖標添加數字提示:self.tabBarItem.badgeValue = 8;

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved