在代码的日子里希望你我同行!

关于iOS应用程序开发过程中如何快捷创建TabBar!

关于iOS应用程序开发过程中如何快捷创建TabBar!
关于iOS应用程序开发工程中如何判断当前App是第一次运行

// window - 大小
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// window - 背景颜色
self.window.backgroundColor = [UIColor whiteColor];
// window - 为主视图
[self.window makeKeyAndVisible];

    // VC 数组
    NSArray *classArray = @[@"YIem_One_TabBar_Home_ViewController", @"YIem_Two_TabBar_Home_ViewController", @"YIem_Three_TabBar_Home_ViewController"];
    // Title 数组
    NSArray *titleArray = @[@"- 推荐 -", @"- ⊙▂⊙ -", @"- 设置 -"];
    // Photo 数组 未选中
    NSArray *photoArray = @[@"one_2.png", @"two_2.png", @"three_2.png"];
    // Photo 数组 选中
    NSArray *photoSelectedArray = @[@"one_1.png", @"two_1.png", @"three_1.png"];
    // Bar 数组
    NSMutableArray *tabBarArr = [NSMutableArray array];
    // 循环输出 Bar
    for (NSInteger i = 0; i < titleArray.count; i++) {
        Class v = NSClassFromString(classArray[i]);
        UIViewController *vc = [[[v class] alloc] init];
        UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
        nc.tabBarItem = [[UITabBarItem alloc] initWithTitle:titleArray[i] image:[[UIImage imageNamed:photoArray[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:photoSelectedArray[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
   [nc.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:1.0 green:0.3264 blue:0.2772 alpha:1.0], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
        [tabBarArr addObject:nc];
        
        
    }
    // 创建 Bar 视图
    UITabBarController *tabVC = [[UITabBarController alloc] init];
    tabVC.viewControllers = tabBarArr;
    
    // 添加
    self.window.rootViewController = tabVC;

QQ20161014-7.png

发表新评论
Title - Artist
0:00