14
Go to list of users who liked
14
Share on X(Twitter)
Share on Facebook
More than 5 years have passed since last update.
AppDelegate.h
// 以下のように、UITabBarControllerDelegateを追加します@interfaceAppDelegate:UIResponder<UIApplicationDelegate,UITabBarControllerDelegate>すると、以下のデリゲートメソッドが使えるようになります。
AppDelegate.m
// タブが5つあるとき-(void)tabBarController:(UITabBarController*)tabBarControllerdidSelectViewController:(UIViewController*)viewController{[[self.tabBarController.tabBar.subviewslastObject]removeFromSuperview];// ↑これやらないとどんどん増えちゃいます。// 最初のTabBar背景画像は別のメソッドでaddするので、この位置でremoveします。NSString*tabBarImageName=@"";switch(tabBarController.selectedIndex){case0:tabBarImageName=@"tabBar-1.png";break;case1:tabBarImageName=@"tabBar-2.png";break;case2:tabBarImageName=@"tabBar-3.png";break;case3:tabBarImageName=@"tabBar-4.png";break;case4:tabBarImageName=@"tabBar-5.png";break;default:break;}UIImageView*tabBg=[[[UIImageViewalloc]initWithImage:[UIImageimageNamed:tabBarImageName]]autorelease];[self.tabBarController.tabBaraddSubview:tabBg];}ちなみにこの方法は、
タブ切替時にタブの背景すべてを変更するので、タブが5つあるなら、5つのタブ背景画像が必要です。
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme