StoryBoard學習1 tabbar實現

1、建立基於Tabbed Application 項目:(壓縮包中 1.jpg)


2、打開Main.storyboard,拖2個NavigationController到 storyboad中,並加在tabbarController中: (壓縮包中 2.jpg)

3、系統的圖標太難看了,並且!!點擊只能是系統默認的藍色,找了好久,只能用代碼搞定它了,在四個tabbarController中的第一個顯示的tabbarController的viewDidLoad實現如下代碼: (壓縮包中 3.jpg)

static bool isReseted = false;

- (void)resetTabarItemOnlyOnce{

    if (isReseted == false) {

        UITabBarController *tabBarVC = self.tabBarController;

        NSArray *imageArr = @[@"Home",@"Product",@"Cart",@"Self"];

        for (int i=0; i<imageArr.count; i++) {

            UITabBarItem *tabBarItem = [tabBarVC.tabBar.items objectAtIndex:i];

            tabBarItem.selectedImage = [[UIImage imageNamed:STRING_FORMAT(@"%@-on",imageArr[i])] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

            tabBarItem.image = [UIImage imageNamed:STRING_FORMAT(@"%@-off",imageArr[i])];

        }

        isReseted = true;

        NSLog(@"<=== 默認tabbar圖片 ===>");

    }else{

        NSLog(@"<=== 默認tabbar圖片只會執行一次 ===>");

    }

}


字體也一樣:

 NSDictionary *textDic = [NSDictionary dictionaryWithObjectsAndKeys:NavBarColor,NSForegroundColorAttributeName,nil];

[tabBarItem setTitleTextAttributes:textDic forState:UIControlStateSelected];



4、我去,一個下午就這幾句話。。。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章