1、新建项目(无需多说)
2、简单设置一下项目
2.1、图中1将创建项目时随系统的Main删除
2.2、这一块是设置横竖屏转换的,不想项目横屏的取消勾选(我有个项目上线了才发现没有勾掉~~o(>_<)o ~~)
3、开始写代码
在AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//创建window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//初始化一个tabbar控制器
UITabBarController *tabbar = [[UITabBarController alloc] init];
//创建子控制器,根据需求想要几个就创建几个
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor grayColor];
vc1.tabBarItem.title = @"首页";
vc1.tabBarItem.image = [UIImage imageNamed:@"home"];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.view.backgroundColor = [UIColor greenColor];
vc2.tabBarItem.title = @"活动";
vc2.tabBarItem.image = [UIImage imageNamed:@"activity"];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3.view.backgroundColor = [UIColor redColor];
vc3.tabBarItem.title = @"社区";
vc3.tabBarItem.image = [UIImage imageNamed:@"community"];
//添加子控制器到UTabBarController中
tabbar.viewControllers = @[vc1,vc2,vc3];
//设置window为主窗口并显示
[self.window makeKeyAndVisible];
return YES;
}
好啦,代码完事,comment+R运行项目,就这么简单。