我剛開始使用iOS開發,我只是在玩atm。iOS自定義標籤欄
我想將默認的tabbar按鈕轉換爲更自定義的東西。
後一些環顧四周,我發現你可以爲每個按鈕創建自定義的狀態,所以我所做的:
UIImage *selectedImage0 = [UIImage imageNamed:@"first.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"second.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
但是,我無法擺脫的默認按鈕,它改變了形象,但它不會改變我的整個按鈕。
有什麼我需要做的嗎?
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
UIImage *selectedImage0 = [UIImage imageNamed:@"first.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"second.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
http://stackoverflow.com/questions/4710298/how-can-i-create-custom-tab-bar-add-custom-images-in-tab-bar-without-xib-cha...Visit這個堆棧帖子.. – Nit 2012-04-27 05:59:04
請參閱本教程和自定義選項卡欄的源代碼。 [Custom tabbar](http://cocoacontrols.com/search?utf8=%E2%9C%93&q=tabbar) – 2012-04-27 06:13:06
[This answer](http://stackoverflow.com/questions/41139914/how-to-make- multiple-color-tab-bar-in-swift-3/41140329#41140329)可能會有用。 – 2016-12-14 12:24:12