UITabBarController

{

//初始化UITabBarController? (可以輕松地管理多個視圖控制器)

UITabBarController *tabBarControllr = [[UITabBarController alloc] init];

//創(chuàng)建子視圖控制器

FirstViewController *firstVC = [[FirstViewController alloc] init];

//設置標題

firstVC.tabBarItem.title=@"首頁";

//設置圖片---沒選中時顯示的圖片

firstVC.tabBarItem.image= [UIImage imageNamed:@"tabbar_home"];

firstVC.tabBarItem.selectedImage= [UIImage imageNamed:@"tabbar_home_selected"];

//設置提示信息的紅色小圓點

firstVC.tabBarItem.badgeValue=@"3";

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstVC];

firstVC.navigationItem.title= firstVC.tabBarItem.title;

//將子視圖控制器添加到tabBarControllr

//第一種方式

[tabBarControllr addChildViewController:nav];

[tabBarControllr addChildViewController:secondVC];

[tabBarControllr addChildViewController:thirdVC];

[tabBarControllr addChildViewController:fourVC];

[tabBarControllr addChildViewController:fifthVC];

//第二種方式按顯示順序放置

tabBarControllr.viewControllers= @[nav,secondVC,thirdVC,fourVC,firstVC];

//為tabBarControllr選中設置顏色

tabBarControllr.tabBar.tintColor= [UIColorcolor WithRed:253 / 255.0green:128 / 255.0blue:7 / 255.0alpha:1];

//設置tabBarControllr為根視圖控制器

[UIApplicationshared Application].keyWindow.rootViewController= tabBarControllr;

//設置默認顯示視圖控制器頁面從0開始

tabBarControllr.selectedIndex= 3;

//拼接上下層視圖方式

UIImage *image1 = [UIImage imageNamed:@"tabbar_compose_button"];

UIImage *image2 = [UIImage imageNamed:@"tabbar_compose_icon_add"];

UIGraphicsBeginImageContextWithOptions(CGSizeMake(71, 49),NO, 0.0);

[image1 drawInRect:CGRectMake(0, 0, 71, 49)];

[image2 drawInRect:CGRectMake(23, 12, 25, 25)];

UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

//關閉上下文

UIGraphicsGetCurrentContext();

ThirdViewController *thirdVC= [[ThirdViewController alloc]init];

//使用原始圖片

thirdVC.tabBarItem.image= [imageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

thirdVC.tabBarItem.selectedImage= [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//設置圖片偏移量

thirdVC.tabBarItem.imageInsets=UIEdgeInsetsMake(6, 0, -6, 0);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容