// 单例
#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;
}
网友评论