iOS-UI-UITabBarControllerDelegate-标签视图控制器

@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]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];
    

// 创建被NC 管理的页面
RootViewController *RootVC = [[[RootViewController alloc] init]autorelease];
UINavigationController *rootNC = [[[UINavigationController alloc] initWithRootViewController:RootVC] autorelease];
// 为每一个界面设置自己的标题风格
rootNC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:10000] autorelease];
ScondViewController *secVC = [[[ScondViewController alloc] init] autorelease];
UINavigationController *secNC = [[[UINavigationController alloc] initWithRootViewController:secVC] autorelease];
    // 为每一个界面设置自己的标题风格
secNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"垃圾桶" image:[UIImage imageNamed:@"100-coffee.png"]  tag:100000] autorelease];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNC = [[[UINavigationController alloc] initWithRootViewController:thirdVC] autorelease];
    // 为每一个界面设置自己的标题风格
thirdNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"19-gear.png"] selectedImage:[UIImage imageNamed:@"20-gear2.png"]]autorelease];
thirdNC.tabBarItem.badgeValue = @"99+";

// 默认高度49, 5个以上会重叠

UITabBarController *tabBarC = [[UITabBarController alloc] init];
// 重要属性 - 所管理的界面数组
tabBarC.viewControllers = @[rootNC, secNC, thirdNC];
// 提示(99+)
tabBarC.delegate = self;

// 风格属性
// 边框颜色

// tabBarC.tabBar.tintColor = [UIColor greenColor];

tabBarC.tabBar.barTintColor = [UIColor lightGrayColor];
tabBarC.tabBar.backgroundColor = [UIColor blackColor];
// 是否半透明
tabBarC.tabBar.translucent = YES;
// 背景图片
[tabBarC.tabBar setBackgroundImage:[UIImage imageNamed:@"屏幕快照 2016-01-20 下午4.10.46.pngb"]];


self.window.rootViewController = tabBarC;
[tabBarC release];

return YES;

}
//

  • (void)tabBarController:(UITabBarController )tabBarController didSelectViewController:(UIViewController )viewController
    {
    NSLog(@"%ld", tabBarController.selectedIndex);
    // 选择清除提示"99+"
    if (2 == tabBarController.selectedIndex) {

    UINavigationController *navigationC = (UINavigationController *) viewController;
    navigationC.tabBarItem.badgeValue = nil;

    }
    }

iOS-UI-UITabBarControllerDelegate-标签视图控制器
iOS-UI-UITabBarControllerDelegate-标签视图控制器
iOS-UI-UITabBarControllerDelegate-标签视图控制器
iOS-UI-UITabBarControllerDelegate-标签视图控制器
iOS-UI-UITabBarControllerDelegate-标签视图控制器