新建一个项目,
继承
UITabBarController
如.h文件
#import
@interface ZHBaseViewController : UITabBarController
@end
在
-(void)ViewDidLoad{
//调用
[self createView];
[self createTabbar];
}
-(void)createView{
ZHVideoViewController * video = [[ZHVideoViewController alloc]init];
UINavigationController * videoVc = [[UINavigationController alloc]initWithRootViewController:video];
ZHAudioViewController * audio = [[ZHAudioViewController alloc]init];
UINavigationController * audioVc = [[UINavigationController alloc]initWithRootViewController:audio];
ZHPictureViewController * picture = [[ZHPictureViewController alloc]init];
UINavigationController * pictureVc = [[UINavigationController alloc]initWithRootViewController:picture];
self.viewControllers = @[videoVc,audioVc,pictureVc];
}
-(void)createTabbar{
NSArray * ImageArray = @[@"教学研讨-视频_08",@"教学研讨-视频_10",@"教学研讨图文_03"];
NSArray * selectArray = @[@"教学研讨-视频1_08",@"教学研讨-视频1_10",@"教学研讨-图文1_03"];
NSArray * titles = @[@"视频资源",@"音频资源",@"图文资源"];
for ( int i = 0 ; i<3; i++) {
UIImage * orimage = [UIImage imageNamed:ImageArray[i]];
orimage = [orimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage * selectimage = [UIImage imageNamed:selectArray[i]];
selectimage = [selectimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem * item = self.tabBar.items[i];
item = [item initWithTitle:titles[i] image:orimage selectedImage:selectimage];
}
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
}