Objective - C UITabbarController
2015-12-24 21:26
531 查看
//
// RootViewController.m
// UI_12day_UITabbarController
//
// Created by dllo on 15/12/23.
// Copyright © 2015年 dllo. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor cyanColor];
self.title = @"第一页";
self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花荣",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松", @"徐宁", @"张清", @"杨志", @"董平", @"索超", @"戴宗", @"刘唐", @"李逵", @"史进", @"穆弘", @"雷横", @"李俊",nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
[_tableView release];
// 导航视图不透明
self.navigationController.navigationBar.translucent = NO;
// 另一个Cell方式
// tableView的对cell的注册
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 新的Cell方式:用系统的Cell无法加视图,必须通过自定义Cell使用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
cell.textLabel.text = self.arr[indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
///////////////////////////////////////////
AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
// 签协议
@interface AppDelegate ()<UITabBarControllerDelegate>
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor =
[UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
RootViewController *rootVC = [[RootViewController alloc] init];
// navigation用来管理viewController
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
// tabbarController来管理navigation
// 创建一个tabbar的按钮内容,一个按钮对应一个navigation
naVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000] autorelease];
// 显示消息计数
naVC.tabBarItem.badgeValue = @"+99";
// 创建第二个naVC
SecondViewController *secVC = [[SecondViewController alloc] init];
UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC];
secNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"contect" image:
[UIImage imageNamed:@"name.png"]tag:1001];
// 创建第三个naVC
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNAVC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"定位" image:[UIImage imageNamed:@"dingwei.png"] selectedImage:[UIImage imageNamed:@"time.png"]];
// 创建第四个
FouthViewController *fouthVC = [[FouthViewController alloc] init];
UINavigationController *fouthNAVC = [[UINavigationController alloc] initWithRootViewController:fouthVC];
fouthNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1003] autorelease];
// 创建第五个
FifthViewController *fifVC = [[FifthViewController alloc] init];
UINavigationController *fifthNAVC = [[UINavigationController alloc] initWithRootViewController:fifVC];
fifthNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"时间" image:[UIImage imageNamed:@"time.png"] tag:1004];
// 创建第六个
SixthViewController *sixVC = [[SixthViewController alloc] init];
UINavigationController *sixNAVC = [[UINavigationController alloc] initWithRootViewController:sixVC];
sixNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通知" image:[UIImage imageNamed:@"1.jpg"] selectedImage:[UIImage imageNamed:@"2.jpg"]];
// 创建tabbarController
UITabBarController *tabVC = [[UITabBarController alloc] init];
// 设置tabVC管理的naVC
tabVC.viewControllers = @[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];
// 设置window的根视图控制器
self.window.rootViewController =
tabVC;
// 设置代理人
tabVC.delegate = self;
[tabVC release];
[naVC release];
[rootVC release];
[secNAVC release];
[secVC release];
[thirdNAVC release];
[thirdVC release];
[fouthNAVC release];
[fouthVC release];
[fifthNAVC release];
[fifVC release];
[sixNAVC release];
[sixVC release];
// 设置一下tabbar的外观
// 修改点击后图标颜色,默认点击为蓝色
tabVC.tabBar.translucent = NO;
tabVC.tabBar.tintColor = [UIColor brownColor];
// 修改bar背景颜色
tabVC.tabBar.barTintColor = [UIColor cyanColor];
return YES;
}
#pragma mark 这个方法相当于tab的点击方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"14111");
// 通过点击,把显示消息的数字取消
viewController.tabBarItem.badgeValue = nil;
}
//
// RootViewController.m
// UI_12day_UITabbarController
//
// Created by dllo on 15/12/23.
// Copyright © 2015年 dllo. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor cyanColor];
self.title = @"第一页";
self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花荣",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松", @"徐宁", @"张清", @"杨志", @"董平", @"索超", @"戴宗", @"刘唐", @"李逵", @"史进", @"穆弘", @"雷横", @"李俊",nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
[_tableView release];
// 导航视图不透明
self.navigationController.navigationBar.translucent = NO;
// 另一个Cell方式
// tableView的对cell的注册
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 新的Cell方式:用系统的Cell无法加视图,必须通过自定义Cell使用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
cell.textLabel.text = self.arr[indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
///////////////////////////////////////////
AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
// 签协议
@interface AppDelegate ()<UITabBarControllerDelegate>
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor =
[UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
RootViewController *rootVC = [[RootViewController alloc] init];
// navigation用来管理viewController
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
// tabbarController来管理navigation
// 创建一个tabbar的按钮内容,一个按钮对应一个navigation
naVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000] autorelease];
// 显示消息计数
naVC.tabBarItem.badgeValue = @"+99";
// 创建第二个naVC
SecondViewController *secVC = [[SecondViewController alloc] init];
UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC];
secNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"contect" image:
[UIImage imageNamed:@"name.png"]tag:1001];
// 创建第三个naVC
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNAVC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"定位" image:[UIImage imageNamed:@"dingwei.png"] selectedImage:[UIImage imageNamed:@"time.png"]];
// 创建第四个
FouthViewController *fouthVC = [[FouthViewController alloc] init];
UINavigationController *fouthNAVC = [[UINavigationController alloc] initWithRootViewController:fouthVC];
fouthNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1003] autorelease];
// 创建第五个
FifthViewController *fifVC = [[FifthViewController alloc] init];
UINavigationController *fifthNAVC = [[UINavigationController alloc] initWithRootViewController:fifVC];
fifthNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"时间" image:[UIImage imageNamed:@"time.png"] tag:1004];
// 创建第六个
SixthViewController *sixVC = [[SixthViewController alloc] init];
UINavigationController *sixNAVC = [[UINavigationController alloc] initWithRootViewController:sixVC];
sixNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通知" image:[UIImage imageNamed:@"1.jpg"] selectedImage:[UIImage imageNamed:@"2.jpg"]];
// 创建tabbarController
UITabBarController *tabVC = [[UITabBarController alloc] init];
// 设置tabVC管理的naVC
tabVC.viewControllers = @[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];
// 设置window的根视图控制器
self.window.rootViewController =
tabVC;
// 设置代理人
tabVC.delegate = self;
[tabVC release];
[naVC release];
[rootVC release];
[secNAVC release];
[secVC release];
[thirdNAVC release];
[thirdVC release];
[fouthNAVC release];
[fouthVC release];
[fifthNAVC release];
[fifVC release];
[sixNAVC release];
[sixVC release];
// 设置一下tabbar的外观
// 修改点击后图标颜色,默认点击为蓝色
tabVC.tabBar.translucent = NO;
tabVC.tabBar.tintColor = [UIColor brownColor];
// 修改bar背景颜色
tabVC.tabBar.barTintColor = [UIColor cyanColor];
return YES;
}
#pragma mark 这个方法相当于tab的点击方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"14111");
// 通过点击,把显示消息的数字取消
viewController.tabBarItem.badgeValue = nil;
}
// RootViewController.m
// UI_12day_UITabbarController
//
// Created by dllo on 15/12/23.
// Copyright © 2015年 dllo. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor cyanColor];
self.title = @"第一页";
self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花荣",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松", @"徐宁", @"张清", @"杨志", @"董平", @"索超", @"戴宗", @"刘唐", @"李逵", @"史进", @"穆弘", @"雷横", @"李俊",nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
[_tableView release];
// 导航视图不透明
self.navigationController.navigationBar.translucent = NO;
// 另一个Cell方式
// tableView的对cell的注册
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 新的Cell方式:用系统的Cell无法加视图,必须通过自定义Cell使用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
cell.textLabel.text = self.arr[indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
///////////////////////////////////////////
AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
// 签协议
@interface AppDelegate ()<UITabBarControllerDelegate>
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor =
[UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
RootViewController *rootVC = [[RootViewController alloc] init];
// navigation用来管理viewController
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
// tabbarController来管理navigation
// 创建一个tabbar的按钮内容,一个按钮对应一个navigation
naVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000] autorelease];
// 显示消息计数
naVC.tabBarItem.badgeValue = @"+99";
// 创建第二个naVC
SecondViewController *secVC = [[SecondViewController alloc] init];
UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC];
secNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"contect" image:
[UIImage imageNamed:@"name.png"]tag:1001];
// 创建第三个naVC
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNAVC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"定位" image:[UIImage imageNamed:@"dingwei.png"] selectedImage:[UIImage imageNamed:@"time.png"]];
// 创建第四个
FouthViewController *fouthVC = [[FouthViewController alloc] init];
UINavigationController *fouthNAVC = [[UINavigationController alloc] initWithRootViewController:fouthVC];
fouthNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1003] autorelease];
// 创建第五个
FifthViewController *fifVC = [[FifthViewController alloc] init];
UINavigationController *fifthNAVC = [[UINavigationController alloc] initWithRootViewController:fifVC];
fifthNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"时间" image:[UIImage imageNamed:@"time.png"] tag:1004];
// 创建第六个
SixthViewController *sixVC = [[SixthViewController alloc] init];
UINavigationController *sixNAVC = [[UINavigationController alloc] initWithRootViewController:sixVC];
sixNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通知" image:[UIImage imageNamed:@"1.jpg"] selectedImage:[UIImage imageNamed:@"2.jpg"]];
// 创建tabbarController
UITabBarController *tabVC = [[UITabBarController alloc] init];
// 设置tabVC管理的naVC
tabVC.viewControllers = @[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];
// 设置window的根视图控制器
self.window.rootViewController =
tabVC;
// 设置代理人
tabVC.delegate = self;
[tabVC release];
[naVC release];
[rootVC release];
[secNAVC release];
[secVC release];
[thirdNAVC release];
[thirdVC release];
[fouthNAVC release];
[fouthVC release];
[fifthNAVC release];
[fifVC release];
[sixNAVC release];
[sixVC release];
// 设置一下tabbar的外观
// 修改点击后图标颜色,默认点击为蓝色
tabVC.tabBar.translucent = NO;
tabVC.tabBar.tintColor = [UIColor brownColor];
// 修改bar背景颜色
tabVC.tabBar.barTintColor = [UIColor cyanColor];
return YES;
}
#pragma mark 这个方法相当于tab的点击方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"14111");
// 通过点击,把显示消息的数字取消
viewController.tabBarItem.badgeValue = nil;
}
//
// RootViewController.m
// UI_12day_UITabbarController
//
// Created by dllo on 15/12/23.
// Copyright © 2015年 dllo. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor cyanColor];
self.title = @"第一页";
self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花荣",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松", @"徐宁", @"张清", @"杨志", @"董平", @"索超", @"戴宗", @"刘唐", @"李逵", @"史进", @"穆弘", @"雷横", @"李俊",nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
[_tableView release];
// 导航视图不透明
self.navigationController.navigationBar.translucent = NO;
// 另一个Cell方式
// tableView的对cell的注册
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 新的Cell方式:用系统的Cell无法加视图,必须通过自定义Cell使用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
cell.textLabel.text = self.arr[indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
///////////////////////////////////////////
AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
// 签协议
@interface AppDelegate ()<UITabBarControllerDelegate>
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor =
[UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
RootViewController *rootVC = [[RootViewController alloc] init];
// navigation用来管理viewController
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
// tabbarController来管理navigation
// 创建一个tabbar的按钮内容,一个按钮对应一个navigation
naVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000] autorelease];
// 显示消息计数
naVC.tabBarItem.badgeValue = @"+99";
// 创建第二个naVC
SecondViewController *secVC = [[SecondViewController alloc] init];
UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC];
secNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"contect" image:
[UIImage imageNamed:@"name.png"]tag:1001];
// 创建第三个naVC
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNAVC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"定位" image:[UIImage imageNamed:@"dingwei.png"] selectedImage:[UIImage imageNamed:@"time.png"]];
// 创建第四个
FouthViewController *fouthVC = [[FouthViewController alloc] init];
UINavigationController *fouthNAVC = [[UINavigationController alloc] initWithRootViewController:fouthVC];
fouthNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1003] autorelease];
// 创建第五个
FifthViewController *fifVC = [[FifthViewController alloc] init];
UINavigationController *fifthNAVC = [[UINavigationController alloc] initWithRootViewController:fifVC];
fifthNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"时间" image:[UIImage imageNamed:@"time.png"] tag:1004];
// 创建第六个
SixthViewController *sixVC = [[SixthViewController alloc] init];
UINavigationController *sixNAVC = [[UINavigationController alloc] initWithRootViewController:sixVC];
sixNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通知" image:[UIImage imageNamed:@"1.jpg"] selectedImage:[UIImage imageNamed:@"2.jpg"]];
// 创建tabbarController
UITabBarController *tabVC = [[UITabBarController alloc] init];
// 设置tabVC管理的naVC
tabVC.viewControllers = @[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];
// 设置window的根视图控制器
self.window.rootViewController =
tabVC;
// 设置代理人
tabVC.delegate = self;
[tabVC release];
[naVC release];
[rootVC release];
[secNAVC release];
[secVC release];
[thirdNAVC release];
[thirdVC release];
[fouthNAVC release];
[fouthVC release];
[fifthNAVC release];
[fifVC release];
[sixNAVC release];
[sixVC release];
// 设置一下tabbar的外观
// 修改点击后图标颜色,默认点击为蓝色
tabVC.tabBar.translucent = NO;
tabVC.tabBar.tintColor = [UIColor brownColor];
// 修改bar背景颜色
tabVC.tabBar.barTintColor = [UIColor cyanColor];
return YES;
}
#pragma mark 这个方法相当于tab的点击方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"14111");
// 通过点击,把显示消息的数字取消
viewController.tabBarItem.badgeValue = nil;
}
相关文章推荐
- Objective-C 省市区 三个tableView联动
- 【Objective-C学习记录】第二十三天
- Objective-C 集合之NSDictionary的常用方法
- Objective - C tableView自适应高度 & KVC (Key -Value-Coding)
- Objective-C tableView自定义cell
- How to call an Objective-C Method from a C Method?
- Objective - C UITableView界面传值 从前往后,从后往前
- Objective - C UITableView学习笔记
- 【转】Android自动化测试(UiAutomator)——UiObject
- java线程同步:使用Object的wait,notify,notifyAll做线程调度
- Objective--C 导航视图控制器
- Objective-C基础1-类目(Category)和延展(Extension)的区别
- Objective-C 集合之NSArray的常用方法
- Objective-C NSObject 的实现分析(2014-10-23更新)
- Objective-C Runtime 总结:消息机制 篇
- Object.ReferenceEquals
- 遍历系统的所有ObjectType和TypeIndex
- iOS开发系列--Objective-C之KVC、KVO
- Objective-c语言_内存管理2(代码)
- Objective-C 和 Core Foundation 对象相互转换的内存管理总结