1:主程序底部TabBar的功能实现效果图: 主要代码如下:- (UITabBarController*)setRootVC:(BOOL)bShowCart{ //创建一个子控制器 用于显示当前的tab TabHomeVC *homeVC = [[TabHomeVC al ...
1:主程序底部TabBar的功能实现
效果图:
主要代码如下:
- (UITabBarController*)setRootVC:(BOOL)bShowCart{ //创建一个子控制器 用于显示当前的tab TabHomeVC *homeVC = [[TabHomeVC alloc] init]; //每个tab都是一个nav的内容,这样每个都是自个的nav,进行跳转 UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC]; UIImage *unselectedImage = [UIImage imageNamed:@"tab-home"]; UIImage *selectedImage = [UIImage imageNamed:@"tab-home-s"]; homeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; homeVC.tabBarItem.tag = 0; TabProductVC *proVC = [[TabProductVC alloc] init]; UINavigationController *proNav = [[UINavigationController alloc] initWithRootViewController:proVC]; unselectedImage = [UIImage imageNamed:@"tab-pro"]; selectedImage = [UIImage imageNamed:@"tab-pro-s"]; proNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"所有商品" image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; proNav.tabBarItem.tag = 1; TabNewestVC * newVc = [[TabNewestVC alloc] init]; UINavigationController * newNav = [[UINavigationController alloc] initWithRootViewController:newVc]; unselectedImage = [UIImage imageNamed:@"tab-new"]; selectedImage = [UIImage imageNamed:@"tab-new-s"]; newNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"最新揭晓" image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; newNav.tabBarItem.tag = 2; TabShopCartVC * cartVc = [[TabShopCartVC alloc] init]; UINavigationController * cartNav = [[UINavigationController alloc] initWithRootViewController:cartVc]; unselectedImage = [UIImage imageNamed:@"tab-cart"]; selectedImage = [UIImage imageNamed:@"tab-cart-s"]; cartNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"购物车" image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; cartNav.tabBarItem.tag = 3; TabMineVC * mineVc = [[TabMineVC alloc] init]; UINavigationController * mineNav = [[UINavigationController alloc] initWithRootViewController:mineVc]; unselectedImage = [UIImage imageNamed:@"tab-mine"]; selectedImage = [UIImage imageNamed:@"tab-mine-s"]; mineNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的云购" image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; mineNav.tabBarItem.tag = 4; //把上面的控制器增加到uitabbarcontroller的数组里 UITabBarController *tabBarController = [[UITabBarController alloc] init]; if(bShowCart) tabBarController.viewControllers = @[homeNav,proNav,newNav,cartNav,mineNav]; else tabBarController.viewControllers = @[homeNav,proNav,newNav,mineNav]; tabBarController.delegate = self; //设置一些样式内容 // customise TabBar UI Effect [UITabBar appearance].tintColor = BG_COLOR; [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:TABBAR_TEXT_NOR_COLOR} forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:TABBAR_TEXT_HLT_COLOR} forState:UIControlStateSelected]; // customise NavigationBar UI Effect [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithRenderColor:NAVBAR_COLOR renderSize:CGSizeMake(10., 10.)] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.],NSForegroundColorAttributeName:[UIColor blackColor]}]; UITabBar *tabBar = tabBarController.tabBar; tabBar.backgroundColor = BG_COLOR; return tabBarController;}- (void)setCartNum{ //获得UITabBarController UITabBarController* tabVC = (UITabBarController*)self.window.rootViewController; //获得其中第四个 也就是购物车那个tabbar UINavigationController* navVC = [tabVC.viewControllers objectAtIndex:3]; __weak typeof (navVC) wNav = navVC; //给它增加一个数字标识 [CartModel quertCart:nil value:nil block:^(NSArray* result){ if(result.count > 0) wNav.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",(int)result.count]; else wNav.tabBarItem.badgeValue = nil; }];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]]; //加载初始化的那个tab UIViewController *rootViewController = [self setRootVC:YES]; [[self window] setRootViewController:rootViewController]; //显示是否有数字标识 [self setCartNum]; // set backgroundColor [[self window] setBackgroundColor:[UIColor whiteColor]]; // set makeKeyAndVisible [[self window] makeKeyAndVisible]; return YES;}
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:主程序底部TabBar功能跟登录页面布局
关键词:登录
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。