Movatterモバイル変換


[0]ホーム

URL:


LoginSignup
14

Go to list of users who liked

14

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

タブバーの背景画像を設定する方法

Last updated atPosted at 2012-05-13
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つのタブ背景画像が必要です。

14

Go to list of users who liked

14
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14

Go to list of users who liked

14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?


[8]ページ先頭

©2009-2025 Movatter.jp