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
网友评论