你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS UITabBartroller作為根視圖

iOS UITabBartroller作為根視圖

編輯:IOS開發綜合

//

// RootViewController.m

// UITabBarCOntrollerDemo

//

// Created by Dubai on 14/10/4.

// Copyright (c) 2015年 DUbai. All rights reserved.

//

 

#import "RootViewController.h"

 

#import "HomeViewController.h"

#import "FindViewController.h"

#import "CategoryViewController.h"

#import "ShoppingViewController.h"

#import "UserViewController.h"

#import "SettingViewController.h"

 

@interface RootViewController ()

 

@end

 

@implementation RootViewController

 

-(void)viewWillAppear:(BOOL)animated

{

[superviewWillAppear:animated];

self.navigationController.navigationBar.translucent = NO;

self.title =@"123";

 

 

}

 

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColorgreenColor];

 

 

//首頁

HomeViewController *homeVc = [[HomeViewControlleralloc] init];

UINavigationController *homeNC = [[UINavigationControlleralloc] initWithRootViewController:homeVc];

 

homeNC.tabBarItem.title =@"首頁";//53

homeNC.tabBarItem.image = [UIImageimageNamed:@"53-house.png"];//用在標簽上的圖片不呢過隨便給,必須30*30高清屏 60 *60 (可以有浮動 27 *27 55 * 55 62*62)

homeNC.tabBarItem.badgeValue =@"12";//提示信息

 

//分類

CategoryViewController *categoryVC = [[CategoryViewControlleralloc] init];

UINavigationController *categoryNC = [[UINavigationControlleralloc] initWithRootViewController:categoryVC];

categoryNC.tabBarItem.title =@"分類";//06

categoryNC.tabBarItem.image = [UIImageimageNamed:@"06-magnifying-glass.png"];

 

 

//發現

FindViewController *findVC = [[FindViewControlleralloc] init];

UINavigationController *findNC = [[UINavigationControlleralloc] initWithRootViewController:findVC];

findNC.tabBarItem.title =@"發現";//12

findNC.tabBarItem.image = [UIImageimageNamed:@"12-eye.png"];

 

// findNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:(UITabBarSystemItemSearch) tag:0];//可以自定義標簽(系統的自帶圖片)

 

//購物車

ShoppingViewController *shopVC = [[ShoppingViewControlleralloc] init];

UINavigationController *shopNC = [[UINavigationControlleralloc] initWithRootViewController:shopVC];

shopNC.tabBarItem.title =@"購物車";//80

shopNC.tabBarItem.image = [UIImageimageNamed:@"80-shopping-cart.png"];

 

//用戶

UserViewController *userVC =[[UserViewControlleralloc] init];

UINavigationController *userNC =[[UINavigationControlleralloc] initWithRootViewController:userVC];

userNC.tabBarItem.title =@"我的";//22www.2cto.com

userNC.tabBarItem.image = [UIImageimageNamed:@"22-skull-n-crossbones.png"];

 

 

//設置

SettingViewController *setVC = [[SettingViewControlleralloc] init];

UINavigationController *setNV = [[UINavigationControlleralloc] initWithRootViewController:setVC];

 

setNV.tabBarItem.title =@"設置";

setNV.tabBarItem.image = [UIImageimageNamed:@"19-gear.png"];//默認是五個.其他的隱藏

//將創建的controller添加到tabBarController中管理(模塊添加)

//標簽設置的圖片背景透明(镂空中間扣掉,看到的藍色是透過來的藍色)

self.viewControllers =@[homeNC,categoryNC,findNC,shopNC,userNC,setNV];

 

 

 

//標簽欄的顏色

self.tabBar.barTintColor = [UIColorgreenColor];//可以統一設置

//tabVC.tabBar.backgroundColor = [UIColor redColor];

self.tabBar.tintColor = [UIColorredColor];//被選中的標簽的顏色

//tabVC.tabBar.backgroundImage = [UIImage imageNamed:@"he.png"];//320 *49

self.selectedIndex =2;//設置首先被選擇的標簽.

//tabVC.tabBar.backgroundImage = [UIImage imageNamed:@"he.png"];//標簽欄設置背景圖片

 

//UIAppearance協議提供統一設置的方法

//不是所有屬性都支持統一設置,tintColor就不支持.

//[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];

//[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"ni.png"] forBarMetrics:(UIBarMetricsDefault)];

}

 

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// 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



\

切記: 不要 再把UITabBarController作為導航控制器根視圖了...

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