易采站长站为您分析iOS开发中UITabBarController的使用示例,代码基于Objective-C进行演示,需要的朋友可以参考下
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
#pragma mark - 设置tabBarItem
#pragma mark 第一个视图ViewController
HMT_AViewController * tabBarViewA = [[HMT_AViewController alloc] init];
// 设置A视图下----标签栏标题文字(可参照微信或者QQ体会)
tabBarViewA.tabBarItem.title = @"微信";
// 设置A视图下----标签栏图片(因为自己没有图片,在这里随便设置了个名字)
//tabBarViewA.tabBarItem.image = [UIImage imageNamed:@"1.png"];
// 设置A视图下----标签栏信息提示(住:badgeValue是NSString类型 如下设置了3,就像QQ消息有3条未接受一样,给人一种提醒)
tabBarViewA.tabBarItem.badgeValue = @"3";
// ios7弃用了----标签栏选中的时候显示一张图片,没选中的时候显示另一张图片
//[tabBarViewA.tabBarItem setFinishedSelectedImage:actionMenu.selectedIcon withFinishedUnselectedImage:actionMenu.icon];
// ios7的方法(自己没有图片,所以代码里面的图片都是一个随便取的名字,没有实用意义)
//tabBarViewA.tabBarItem.selectedImage = actionMenu.selectedIcon;
#pragma mark 第二个视图ViewController
// 第二个视图ViewController
HMT_BViewController * tabBarViewB = [[HMT_BViewController alloc] init];
// 设置B视图下----标签栏
// 用系统提供的标识(可以算等价于图标和文字)进行设置(参数:UITabBarSystemItem是个枚举值,想要什么形式,就去系统提供的API中找)
tabBarViewB.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1];
// 设置B视图下----标签栏信息提示
首先我们看一下它的view层级图:
复制代码- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
#pragma mark - 设置tabBarItem
#pragma mark 第一个视图ViewController
HMT_AViewController * tabBarViewA = [[HMT_AViewController alloc] init];
// 设置A视图下----标签栏标题文字(可参照微信或者QQ体会)
tabBarViewA.tabBarItem.title = @"微信";
// 设置A视图下----标签栏图片(因为自己没有图片,在这里随便设置了个名字)
//tabBarViewA.tabBarItem.image = [UIImage imageNamed:@"1.png"];
// 设置A视图下----标签栏信息提示(住:badgeValue是NSString类型 如下设置了3,就像QQ消息有3条未接受一样,给人一种提醒)
tabBarViewA.tabBarItem.badgeValue = @"3";
// ios7弃用了----标签栏选中的时候显示一张图片,没选中的时候显示另一张图片
//[tabBarViewA.tabBarItem setFinishedSelectedImage:actionMenu.selectedIcon withFinishedUnselectedImage:actionMenu.icon];
// ios7的方法(自己没有图片,所以代码里面的图片都是一个随便取的名字,没有实用意义)
//tabBarViewA.tabBarItem.selectedImage = actionMenu.selectedIcon;
#pragma mark 第二个视图ViewController
// 第二个视图ViewController
HMT_BViewController * tabBarViewB = [[HMT_BViewController alloc] init];
// 设置B视图下----标签栏
// 用系统提供的标识(可以算等价于图标和文字)进行设置(参数:UITabBarSystemItem是个枚举值,想要什么形式,就去系统提供的API中找)
tabBarViewB.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1];
// 设置B视图下----标签栏信息提示










