上部导航UINavigationController和下部UITabBarControllerr之间的区别
UINavigationController
使用栈进行管理,管理具有层级关系的视图,使用pus和pop进行层级之间的推出和返回 window的根视图控制器是Navc,初始化将视图交给navc作为根视图控制器,然后让其作为windo w的根视图。
TUITabBarController:
管理没有层级关系的视图,window的根视图控制器是tabBar,初始化只有“init”,使用viewControllers属性添加管理的视图
1:视图的创建因为是多视图的管理,需要创建多视图
//下面代码图很详细,我是简单的创建一个ViewCotroller的
1:修改标题,使用的属性值tabBar来找到title 这里其实和导航栏很相似的方式
2:初始化的方法有三种,
1):第一种是使用的官方的,官方提供了很多的样式可以供你选择性的使用
UITabBarSystemItemMore,
UITabBarSystemItemFavorites,
UITabBarSystemItemFeatured,
UITabBarSystemItemTopRated,
UITabBarSystemItemRecents,
UITabBarSystemItemContacts,
UITabBarSystemItemHistory,
UITabBarSystemItemBookmarks,
UITabBarSystemItemSearch,
UITabBarSystemItemDownloads,
UITabBarSystemItemMostRecent,
UITabBarSystemItemMostViewed,
这个方式在实际开发当中使用较少,因为这里有个坑,不可以更改样式的名字,因为是给你设置好的。
这种初始化方法里面有用到的参数有:1-样式 2:tag值。tag值就不讲了,就是视图上面控件或者视图设置的唯一标示。
oneVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:(UITabBarSystemItemBookmarks) tag:0];
2):第二种是 经常使用的,这里是 使用了两组图片,进行自定义的操作
需要的参数的:1:自定义的标题,2;自定义的未被选中的图片样式 3:选中状态的图片样式
// 创建图片 取消模板渲染 - 未被选中前
UIImage *oneImage = [UIImage imageNamed:@"carGary.png"];
oneImage = [oneImage imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
// 创建图片 取消模板渲染 - 选中后
UIImage *oneImage1 = [UIImage imageNamed:@"carRed.png"];
oneImage1 = [oneImage1 imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
//添加到其的页面图标 这里的初始化,有三个参数:1-标题 2 :未被选中的样式 3:选中后的样式
oneVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"壹" image:oneImage selectedImage:oneImage1];
注意,这里图片创建的时候,因为是控件本身会对其进行模块化,所以添加上看着不美观,要保持图片的原来的样子还需要对其进行轩然的操作。
3):第三种 这里很少使用,可以看一下但是不做具体介绍了,看参数应该就知道了。
//初始化方法3 此为不经常使用的 三种参数,标题,图片,tag值
// oneVC.tabBarItem = [[UITabBarItem alloc] initWithTitle: image: tag:]
2 : 然后就是创建UITabBarControllerr
创建他,系统只有一个方法初始化,就是allod和init
初始化完毕之后使用viewControllers添加要管理的视图 这里要给的是数组的形式
然后让window的根视图等于他。这里一个简单的UITabBarControllerr就创建完毕了