您的位置:首页 > 移动开发 > IOS开发

iOS编程(1)TabBarController

2016-05-31 08:27 323 查看

一、介绍

最近闲着没事干,找了个做iOS端的实习,需要实现一个给情侣用的app的iOS版本,这里简单记录一下每天的工作

二、工作

第一天主要做了这几件事情:(1)github上开启一个新项目,用于版本控制(2)用代码写一个TabBarController

接下来主要说一些TabBarController怎么实现,TabBarController就是下面的几个小栏



如图,TabBarController有4个ViewController,初始化如下

UITabBarController *rootTabBarView = [[UITabBarController alloc] init];
rootTabBarView.viewControllers = @[lovingViewNav, discoverViewNav, chattingViewNav, meViewNav];
rootTabBarView.tabBar.tintColor = [UIColor colorWithRed:0.07 green:0.73 blue:0.02 alpha:1.0];
rootTabBarView.tabBar.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];


主要是前两行,把ViewController加入TabBarView,其实加入的是NavigationController,接下来说一下lovingViewNav这些是怎么做的

就拿lovingViewNav来当例子,这是一个以lovingViewController为RootViewController的NavigationController。NavigationController有一个tabBarItem的属性,该属性用于设置,在加入TabBarController后代表这个ViewController的tabBarItem即图案的图片,图片嵌入位置等信息(这里我主要用了这两个,还有别的属性可以通过option+单击代码中tabBarItem查询)实现代码如下:

//LovingView
self.lovingViewController = [[LovingViewController alloc] init];
UINavigationController *lovingViewNav = [[UINavigationController alloc] initWithRootViewController:self.lovingViewController];
lovingViewNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:lovingViewTitle
image:[[UIImage imageNamed:@"menu_love"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
selectedImage:[[UIImage imageNamed:@"menu_love_on"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
lovingViewNav.tabBarItem.imageInsets = UIEdgeInsetsMake(6.0, 0.0, -6.0, 0.0);


三、微小的工作

这里主要记录一下一些小的事情

(1)不使用storyboard需要在AppDelegate中加入下面几行代码

初始化window和设置可见,同时还要设置window的初始视图

//Initial
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//Set Root View
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:rootTabBarView];
self.window.rootViewController = rootNav;


同时还需要在Info.plist中把Main.storyboard的那一项删去

(2)删除storyboard的时候不小心把LaunchScreen的storyboard也删除了,整个app变成了3.5寸大小,后面新建了之后,并且在Info.plist设置Launch screen interface file base name就没事了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: