美文网首页
ios tabbar

ios tabbar

作者: Lee坚武 | 来源:发表于2019-12-27 10:08 被阅读0次

    import "ViewController.h"

    import "HomeViewController.h"//首页

    import "MessageViewController.h"//信息披露

    import "LifeViewController.h"//生活

    import "MineViewController.h"//我的

    @interface ViewController ()

    @end

    @implementation ViewController

    • (void)viewDidLoad {
      [super viewDidLoad];

      //试图数组
      NSArray* controllerArr = @[@"HomeViewController",@"MessageViewController",@"LifeViewController",@"MineViewController"];
      //标题数组
      NSArray* titleArr = @[@"首页",@"信息披露",@"生活",@"我的"];
      //图片数组
      NSArray* picArr = @[@"home",@"info",@"life",@"my"];
      NSArray* xzpicArr = @[@"home-a",@"info-a",@"life-a",@"my-a"];

      NSMutableArray* array = [[NSMutableArray alloc]init];

      for(int i=0; i<picArr.count; i++)
      {
      Class cl=NSClassFromString(controllerArr[i]);

        UIViewController* controller = [[cl alloc]init];
        UINavigationController* nv = [[UINavigationController alloc]initWithRootViewController:controller];
       controller.title = titleArr[i];
       nv.tabBarItem.image = [[UIImage imageNamed:[NSString stringWithFormat:@"%@",picArr[i]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //设置选中时的图片
        nv.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@",xzpicArr[i]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //设置选中时字体的颜色(也可更改字体大小)
        [nv.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
        
        [array addObject:nv];
        
        
    }
    
    
    self.viewControllers = array;
    

    }

    @end

    相关文章

      网友评论

          本文标题:ios tabbar

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