关闭

iOS(三)实现App底部TabBar的切换:一

284人阅读 评论(0) 收藏 举报
分类:

先上图:

                                

然后添加几个文件
HomeViewController.h

#import <UIKit/UIKit.h>

@interface HomeViewController:UIViewController


@end


HomeViewController.m

#import "HomeViewController.h"

@interface HomeViewController()


@end

@implementation HomeViewController

-(void)viewDidLoad{

    [super viewDidLoad];

    self.title=@"主页";

}

-(void)didReceiveMemoryWarning{

    [super didReceiveMemoryWarning];

}


ClassViewController.h
ClassViewController.m

PrivateViewController.h
PrivateViewController.m
与上面的类似,除了self.title的值不一样

接着修改ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UITabBarController //继承的对象不一样了

@end


ViewController.m

#import "ViewController.h"

#import "PrivateViewController.h"

#import "ClassViewController.h"

#import "HomeViewController.h"

@interface ViewController ()

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    [self createViewControllers];

    // Do any additional setup after loading the view, typically from a nib.

}


-(void)createViewControllers{

    ClassViewController *ClassVC=[[ClassViewController alloc]init];

    PrivateViewController *PrivateVC=[[PrivateViewController alloc]init];

    HomeViewController *HomeVC=[[HomeViewController alloc]init];

    

    NSArray *VCarray=@[HomeVC,ClassVC,PrivateVC];

    NSArray *titlearray=@[@"首页",@"分类",@"个人"];

    NSArray *imagearray=@[@"home",@"classify",@"person"];

    NSMutableArray *UINavi=[[NSMutableArray alloc]initWithCapacity:3];

    

    for (int i=0; i<3; i++) {

        UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:VCarray[i]];

        navi.tabBarItem.title=titlearray[i];

        [navi.tabBarItem setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor blackColor]}  forState:UIControlStateNormal];

        navi.tabBarItem.image=[UIImage imageNamed:imagearray[i]];

        [UINavi addObject:navi];

    }

    self.viewControllers=UINavi;

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12035次
    • 积分:284
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论