- (void)creatTabbar
{
UITabBarController* rootVC = [[UITabBarController alloc] init];
//类、标题、图片、点击时的图片
NSArray* classNames = @[@"YQLimitFreeViewController",@"YQSaleViewController",@"YQFreeViewController",@"YQSubViewController",@"YQHotViewController"];
NSArray* titles = @[@"限免",@"降价",@"免费",@"专题",@"热榜"];
NSArray* imageNames = @[@"tabbar_limitfree",@"tabbar_reduceprice",@"tabbar_appfree",@"tabbar_subject",@"tabbar_rank"];
NSArray* selectImageNames = @[@"tabbar_limitfree_press",@"tabbar_reduceprice_press",@"tabbar_appfree_press",@"tabbar_subject_press",@"tabbar_rank_press"];
//tabbar的子视图数组
NSMutableArray* childVCs = [[NSMutableArray alloc] init];
for (int i=0; i<classNames.count; i++) {
//通过数组取“类”
NSString* className = classNames[i];
Class name = NSClassFromString(className);
//子类实例化父类的实例(多态)
YQRootViewController* VC = [[name alloc] init];
NSString* imageName = imageNames[i];
NSString* selectImageName = selectImageNames[i];
UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:titles[i] image:[UIImage imageNamed:imageName] selectedImage:[UIImage imageNamed:selectImageName]];
[VC setTabBarItem:item];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:VC];
[childVCs addObject:nav];
}
[rootVC.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_bg"]];
[rootVC setViewControllers:childVCs];
self.window.rootViewController = rootVC;
}
UITabBarController
最新推荐文章于 2015-09-11 15:07:10 发布