从一个登陆页跳转到一个具有多个导航页面的工具栏控制器UITabbarController中

Dear 丶 2022-08-08 15:47 189阅读 0赞

方法如下:

(一)新建一个继承于UITabBarController控制器的控制器,在内部绑定多个以视图控制器进行初始化的导航控制器

(二)在登录的事件中创建一个新的上述的控制器对象 直接跳转即可

新建工具栏控制器如下:

编辑LayoutViewController.h如下:

  1. //
  2. // LayoutViewController.h
  3. // 作业整理
  4. //
  5. // Created by apple on 15/9/15.
  6. // Copyright (c) 2015年 LiuXun. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @interface LayoutViewController : UITabBarController
  10. @end

编辑 LayoutViewController.m如下:

  1. //
  2. // LayoutViewController.m
  3. // 作业整理
  4. //
  5. // Created by apple on 15/9/15.
  6. // Copyright (c) 2015年 LiuXun. All rights reserved.
  7. //
  8. #import "LayoutViewController.h"
  9. @interface LayoutViewController ()
  10. @end
  11. @implementation LayoutViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. self.tabBar.barTintColor = [UIColor blueColor];
  15. ViewController *vc1 = [[ViewController alloc] init];
  16. [self TabVC:self setVC:vc1 withTabTitle:@"记录" withTabImgName:@"记录" withSecTabImgNam:@"记录1"];
  17. ChatViewController *vc2 = [[ChatViewController alloc] init];
  18. [self TabVC:self setVC:vc2 withTabTitle:@"交流" withTabImgName:@"交流" withSecTabImgNam:@"交流1"];
  19. SquareViewController *vc3 = [[SquareViewController alloc] init];
  20. [self TabVC:self setVC:vc3 withTabTitle:@"广场" withTabImgName:@"主题" withSecTabImgNam:@"主题1"];
  21. MoreFormViewController *vc4 = [[MoreFormViewController alloc] init];
  22. [self TabVC:self setVC:vc4 withTabTitle:@"更多" withTabImgName:@"我" withSecTabImgNam:@"我1"];
  23. }
  24. // 将属性设置封装在一个成员方法中
  25. -(void)TabVC:(UITabBarController *)tab1 setVC:(UIViewController *) vc withTabTitle:(NSString *)tabtit withTabImgName:(NSString *) imgNam withSecTabImgNam: (NSString *) secImg
  26. {
  27. UINavigationController *navc= [[UINavigationController alloc] initWithRootViewController:vc];
  28. navc.navigationBar.barTintColor = [UIColor blueColor];
  29. navc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName: [UIFont boldSystemFontOfSize:22]};
  30. navc.tabBarItem.title = tabtit;
  31. navc.tabBarItem.image = [UIImage imageNamed:imgNam];
  32. navc.tabBarItem.selectedImage = [[UIImage imageNamed:secImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  33. [navc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal];
  34. [navc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateSelected];
  35. [tab1 addChildViewController:navc];
  36. }
  37. - (void)didReceiveMemoryWarning {
  38. [super didReceiveMemoryWarning];
  39. // Dispose of any resources that can be recreated.
  40. }
  41. @end

在登陆页调用如下:

  1. layVC = [[LayoutViewController alloc] init];
  2. [self.navigationController pushViewController:layVC animated:YES];

运行结果如下:

Center

发表评论

表情:
评论列表 (有 0 条评论,189人围观)

还没有评论,来说两句吧...

相关阅读