UITabBar
2015-08-12 17:27
561 查看
UITabBar
需要创建多个ViewController
@end
@implementation AppDelegate
(void)dealloc
{
[_window release];
[super dealloc];
}
(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];
[_window release];
// 创建第一个视图控制器对象
FirstViewController *firstVC=[[FirstViewController alloc] init];
// 创建第一个naVC
UINavigationController *firstNaVC=[[UINavigationController alloc] initWithRootViewController:firstVC];
// 创建tabbar上的按钮及其内容
firstVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1000] autorelease];
firstVC.tabBarItem.badgeValue=@”+99”;
// 创建第二个
TwoViewController *twoVC=[[TwoViewController alloc] init];
UINavigationController *twoNaVC=[[UINavigationController alloc] initWithRootViewController:twoVC];
twoVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@”网易” image:[UIImage imageNamed:@”6.png”] selectedImage:[UIImage imageNamed:@”5.png”]] autorelease];
// 创建第三个
ThreeViewController *threeVC=[[ThreeViewController alloc] init];
UINavigationController *threeNaVC=[[UINavigationController alloc] initWithRootViewController:threeVC];
threeVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@”添加” image:[UIImage imageNamed:@”1.png”] tag:1002] autorelease];
// 创建第四个
FourViewController *fourVC=[[FourViewController alloc] init];
UINavigationController *fourNaVC=[[UINavigationController alloc] initWithRootViewController:fourVC];
fourVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1003] autorelease];
// 创建第五个
FiveViewController *fiveVC=[[FiveViewController alloc] init];
UINavigationController *fiveNaVC=[[UINavigationController alloc] initWithRootViewController:fiveVC];
fiveVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1004] autorelease];
// 创建第六个
sixViewController *sixVC=[[sixViewController alloc] init];
UINavigationController *sixNaVC=[[UINavigationController alloc] initWithRootViewController:sixVC];
sixVC.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1005];
}
-(void)tabBarController:(UITabBarController )tabBarController didSelectViewController:(UIViewController )viewController{
// 点哪一个都带一个圈,不好看,不用
// viewController.tabBarItem.badgeValue=@”“;
}
需要创建多个ViewController
import “AppDelegate.h”
import “FirstViewController.h”
import “TwoViewController.h”
import “ThreeViewController.h”
import “FourViewController.h”
import “FiveViewController.h”
import “sixViewController.h”
@interface AppDelegate ()@end
@implementation AppDelegate
(void)dealloc
{
[_window release];
[super dealloc];
}
(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];
[_window release];
// 创建第一个视图控制器对象
FirstViewController *firstVC=[[FirstViewController alloc] init];
// 创建第一个naVC
UINavigationController *firstNaVC=[[UINavigationController alloc] initWithRootViewController:firstVC];
// 创建tabbar上的按钮及其内容
firstVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1000] autorelease];
firstVC.tabBarItem.badgeValue=@”+99”;
// 创建第二个
TwoViewController *twoVC=[[TwoViewController alloc] init];
UINavigationController *twoNaVC=[[UINavigationController alloc] initWithRootViewController:twoVC];
twoVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@”网易” image:[UIImage imageNamed:@”6.png”] selectedImage:[UIImage imageNamed:@”5.png”]] autorelease];
// 创建第三个
ThreeViewController *threeVC=[[ThreeViewController alloc] init];
UINavigationController *threeNaVC=[[UINavigationController alloc] initWithRootViewController:threeVC];
threeVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@”添加” image:[UIImage imageNamed:@”1.png”] tag:1002] autorelease];
// 创建第四个
FourViewController *fourVC=[[FourViewController alloc] init];
UINavigationController *fourNaVC=[[UINavigationController alloc] initWithRootViewController:fourVC];
fourVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1003] autorelease];
// 创建第五个
FiveViewController *fiveVC=[[FiveViewController alloc] init];
UINavigationController *fiveNaVC=[[UINavigationController alloc] initWithRootViewController:fiveVC];
fiveVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1004] autorelease];
// 创建第六个
sixViewController *sixVC=[[sixViewController alloc] init];
UINavigationController *sixNaVC=[[UINavigationController alloc] initWithRootViewController:sixVC];
sixVC.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1005];
pragma mark 按钮创建好了,然后创建一个UITabbarController让所有的按钮显示出来
UITabBarController *tabVC=[[UITabBarController alloc] init]; // tabbarController通过一个数组来管理所有要显示出来的naVC tabVC.viewControllers=@[firstNaVC,twoNaVC,threeNaVC,fourNaVC,fiveNaVC,sixNaVC]; self.window.rootViewController=tabVC; // 对tabbar进行外观设置 tabVC.tabBar.translucent=NO; // 背景颜色 tabVC.tabBar.barTintColor=[UIColor orangeColor]; // 点击之后的选中按钮的颜色 tabVC.tabBar.tintColor=[UIColor redColor]; // 设置代理人 tabVC.delegate=self; // 点击进去在哪一个图标,从0开始的 tabVC.selectedIndex=0; // 释放 [tabVC release]; [firstNaVC release]; [twoNaVC release]; [threeNaVC release]; [fourNaVC release]; [fiveVC release]; [sixNaVC release]; [firstVC release]; [twoVC release]; [threeVC release]; [fourVC release]; [fiveVC release]; [sixVC release]; return YES;
}
-(void)tabBarController:(UITabBarController )tabBarController didSelectViewController:(UIViewController )viewController{
// 点哪一个都带一个圈,不好看,不用
// viewController.tabBarItem.badgeValue=@”“;
viewController.tabBarItem.badgeValue=nil;
}
相关文章推荐
- 统一设计,iOS6也玩扁平化
- 关于UITabBar 显示图片的问题
- 2.UITabBar Navigation
- iOS8 UITabBar图标变蓝色
- UITabBar的简单使用
- UITabBar使用小结
- 【新浪微博项目】04微博项目重写TabBar
- iOS开发UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- UITabBarController 标签栏控制器-IOS开发
- UITabBar
- 搞搞UITabBar——iOS从零单排
- iOS 自定义tabbar
- iOS开发-隐藏Tabbar的一些方法
- iOS7修改UITabBar文本颜色以及解决自定义选中图片显示为默认蓝色的问题
- TabBarItem的图片默认颜色
- Swift自定义UITabBar
- UITabBar
- 解决一切的KLTabBarViewController
- UITabBarItem中图片和文字的设置
- IOS 自定义tabbar,并给tabbar按钮加载网络图片