初始一個程序(UITabBarController為根視圖)

1.UITabBarController的寫法

- (void)tab{
UITabBarController *  tbc = [[UITabBarController alloc]init];
vc1 *v1 = [vc1 new];
v1.title = @"首頁";
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:v1];
UIImage *img1 = [UIImage imageNamed:@"tab1"];
v1.tabBarItem.image = img1;
vc2 *v2 = [vc2 new];
v2.title = @"附近";
vc3 *v3 = [vc3 new];
v3.title = @"搜索";
v3.tabBarItem.badgeValue = @"3";
vc4 *v4 = [vc4 new];
v4.title = @"設(shè)置";
NSArray *arr = @[nc,v2,v3,v4];
tbc.viewControllers = arr;
tbc.selectedIndex = 0;
[tbc.tabBar setTintColor:[UIColor greenColor]];
[tbc.tabBar setBarTintColor:[UIColor orangeColor]];
self.window.rootViewController = tbc;
}

2.StoryboardCode 起始程序TabBarController

UIStoryboard * mainstoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabbar = [mainstoryBoard instantiateInitialViewController];
//首頁故事板
    UIStoryboard * faceStoryboard = [UIStoryboard storyboardWithName:@"Face" bundle:nil];
    UINavigationController * faceNaVC = [faceStoryboard instantiateInitialViewController];
    [faceNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"titleBar"] forBarMetrics:UIBarMetricsDefault];
    faceNaVC.tabBarItem.image = [[UIImage imageNamed:@"dingdan_hui"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    faceNaVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"dingdan_lan"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [faceNaVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:RGBA(168, 168, 168, 1.0)} forState:UIControlStateNormal];
    [faceNaVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:RGBA(0, 170, 239, 1.0)} forState:UIControlStateHighlighted];
FaceViewController  * faceVC = [faceStoryboard instantiateViewControllerWithIdentifier:@"FaceViewController"];

3.頁面都是故事版
想要改變tabbar的圖片和文字

//tabbar顏色
    [[UITabBar appearance] setBarTintColor:[UIColor redColor]];
//去除圖片原有藍色層
    for (UITabBarItem *item in self.tabController.toolbarItems) {
        item.selectedImage = [item.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
    }
// 自定義文字顏色
     [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
     [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,318評論 4 61
  • 滿江紅—賀崤函雅集 ——蕎麥皮 水墨丹青,香猶在,琴聲溪若。 弦飛舞,未聽先醉,古箏橫臥。 一曲梵音禪心...
    蕎麥皮1閱讀 519評論 1 1
  • 1.請不要假裝對我好,我很傻,會當(dāng)真的。 2.誰把誰真的當(dāng)真,誰為誰心疼。 3.愛那么短,遺忘那么長。 4.我還在...
    16aa5fab5f62閱讀 307評論 0 0
  • 靜思3D(四膽2) (內(nèi)部研究)………個 301期1469開391對2 302期2479開241對2 303期24...
    靜思夢彩閱讀 174評論 0 1
  • 篾匠:用竹子剖成的薄片或絲編制用品的手藝人 隨著朔料制品的出現(xiàn),篾制品幾乎被淘汰了。所以,可能現(xiàn)在很多人都沒有用過...
    依米在312閱讀 2,101評論 53 45

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