- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//创建window
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//初始化一个tabBar控制器
UITabBarController * tb = [[UITabBarController alloc]init];
//设置控制器为window的根控制器
self.window.rootViewController = tb;
//创建子控制器
HomeViewController * hv = [[HomeViewController alloc]init];
//创建导航栏,并将子控制器同步
UINavigationController * nhv = [[UINavigationController alloc]initWithRootViewController:hv];
//子控制器的背景颜色
nhv.view.backgroundColor = [UIColor grayColor];
//子控制器的tabBar的标题
nhv.tabBarItem.title = @"首页";
//子控制器的tabBar的图片
nhv.tabBarItem.image = [UIImage imageNamed:@""];
//选中时的图片
nhv.tabBarItem.selectedImage = [UIImage imageNamed:@"[email protected]"];
//子控制器的tabBar的图片右上角的文字
nhv.tabBarItem.badgeValue = @"11";
DiscountViewController * dv = [[DiscountViewController alloc]init];
UINavigationController * ndv = [[UINavigationController alloc]initWithRootViewController:dv];
ndv.tabBarItem.title = @"优惠";
ndv.view.backgroundColor = [UIColor greenColor];
ndv.tabBarItem.image = [UIImage imageNamed:@""];
CollectionViewController * cv = [[CollectionViewController alloc]init];
UINavigationController * ncv = [[UINavigationController alloc]initWithRootViewController:cv];
ncv.view.backgroundColor = [UIColor orangeColor];
ncv.tabBarItem.title = @"收藏";
ncv.tabBarItem.image = [UIImage imageNamed:@""];
SignViewController * sv = [[SignViewController alloc]init];
UINavigationController * nsv = [[UINavigationController alloc]initWithRootViewController:sv];
nsv.view.backgroundColor = [UIColor redColor];
nsv.tabBarItem.title = @"登录";
nsv.tabBarItem.image = [UIImage imageNamed:@""];
tb.tabBar.barTintColor = [UIColor whiteColor];//颜色
//将所有的子控制器加到tabBar上,tabBar作为根控制器
tb.viewControllers = @[nhv,ndv,ncv,nsv];
return YES;
}
self.title = @"";//导航栏的标题
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];//导航栏颜色
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
lab.text = @"";
lab.font = [UIFont systemFontOfSize:25];
lab.textAlignment = NSTextAlignmentCenter;
lab.textColor = [UIColor whiteColor];
self.navigationItem.titleView = lab;//自定义导航栏标题
UIButton * searchBut = [UIButton buttonWithType:UIButtonTypeCustom];//自定因导航栏按钮
searchBut.frame = CGRectMake(0, 0, 40, 40);
[searchBut setTitle:@"搜索" forState:UIControlStateNormal];
[searchBut addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * rigntBut = [[UIBarButtonItem alloc]initWithCustomView:searchBut];
self.navigationItem.rightBarButtonItem = rigntBut;