// 單例
#import <Foundation/Foundation.h>
// 單例類: 單例類可以初始化一個單例對象 他只被初始化一次 (節省內存空間)
// 他的生命周期 和整個程序的生命周期一樣
// 單例一般用來傳值
@interface DateHandle : NSObject
@property(nonatomic,retain)NSString *name;
// 類方法( 單例必須有 )
+ (instancetype)shareHandle;
@end
#import "DateHandle.h"
// 1. 單例對象 放在靜態區
static DateHandle * handle = nil;
@implementation DateHandle
// 2. 實現方法
+(instancetype)shareHandle
{
if (handle == nil) {
handle = [[DateHandle alloc]init];
handle.name = @"張三";
}
return handle;
}
@end
self.label.text = [DateHandle shareHandle].name;
// UITabBarController
// 外表
//[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"6.png"] forBarMetrics:UIBarMetricsDefault];
GreenViewController *greenVC = [[GreenViewController alloc]init];
UINavigationController *greenNC = [[UINavigationController alloc]initWithRootViewController:greenVC];
// 系統的tabBar
greenNC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:100];
RedViewController *redVC = [[RedViewController alloc]init];
UINavigationController *redNC = [[UINavigationController alloc]initWithRootViewController:redVC];
UIImage *image1 = [UIImage imageNamed:@"5.png"];
UIImage *image2 = [UIImage imageNamed:@"6.png"];
redNC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"聯系人" image:image1 selectedImage:image2];
redNC.tabBarItem.badgeValue = @"das";
UITabBarController *tabVC = [[UITabBarController alloc]init];
// 存放 他管理的 Controller
tabVC.viewControllers = @[greenNC,redNC,blueNC,yellowNC,blackNC,purpleNC];
tabVC.delegate = self;
self.window.rootViewController = tabVC;
// 當前位置
tabVC.selectedIndex = 2;
// 改顏色
// tabVC.tabBar.tintColor = [UIColor redColor];
// tabVC.tabBar.barTintColor = [UIColor blackColor];
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
viewController.tabBarItem.badgeValue = nil;
}