美文网首页
iOS tabbar+navgation的项目结构

iOS tabbar+navgation的项目结构

作者: yuezishenyou | 来源:发表于2018-08-21 14:55 被阅读0次

    1.AppDelegate.m

        self.window.frame = [[UIScreen mainScreen] bounds];
        
        self.window.backgroundColor = [UIColor whiteColor];
        
        XGGTabBarController *navc = [[XGGTabBarController alloc] init];
        
        self.window.rootViewController = navc;
        
        [self.window makeKeyAndVisible];
    

    2.UITabBarController.m

    - (void)viewDidLoad {
        [super viewDidLoad];
       
        // 设置标题字体颜色
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];
        // 设置标题字体大小
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:8.0]} forState:UIControlStateNormal];
        
        
     
        [self addChildVC:[[XGGMainController alloc]init] title:@"主页" normalImage:@"friendsRecommentIcon" selectedImage:@"friendsRecommentIcon-click"];
    
        [self addChildVC:[[XGGRealmController alloc]init] title:@"其他" normalImage:@"MainTagSubIcon" selectedImage:@"MainTagSubIconClick"];
        
        [self addChildVC:[[XGGViewController alloc]init] title:@"这个" normalImage:@"nav_coin_icon" selectedImage:@"nav_coin_icon_click"];
    
        
    }
    
    
    
    
    
    - (void)addChildVC:(UIViewController *)controller title:(NSString *)title normalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage
    {
        
        UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:controller];
        
        navc.tabBarItem.title = title;
        
        navc.tabBarItem.image = [[UIImage imageNamed:normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        navc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        controller.navigationItem.title = title;
        
        [self addChildViewController:navc];
    }
    

    3.ViewController.m

       // self.title = @"主页";
        
        self.navigationItem.title = @"主页";
    

    相关文章

      网友评论

          本文标题:iOS tabbar+navgation的项目结构

          本文链接:https://www.haomeiwen.com/subject/kvqjiftx.html