2013-05-07 25 views
7

私はストーリーボードを使用してアプリケーションを作成しましたが、TabBarControllerには5つのタブがあります。 各タブにはタブコンとtab titleがあります。タブが選択されたら、tabbarアイコンを変更したいと思います。 storyboardを使用するにはどうすればよいですか?コードの下ストーリーボードを使用してタブバー選択した画像を変更する方法

+0

あなたはタブバー項目の属性インスペクタに新しい「選択画像」フィールドでこれを行うことができると思いますが、選択されたとき、空白の画像になり、いくつかの理由で、などでしょうとにかくXcode 6.1.1のただし、ここに回避策があります:http://stackoverflow.com/a/26802597/650558 –

答えて

-2

選択でタブバーの画像を変更します:カスタムへ

UITabBarItem *tabBarItem = [[tabbar items] objectAtIndex:0]; 
[tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"img_hover.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"img.png"]]; 

変更識別子と、私はそれを持っている画像enter image description here

+0

私はこのコードを書くべきであるところに5つのタブがあります。それぞれのviewControllerで? – AMohan

+0

' - (void)viewDidLoad' – Ashini

1

を追加します。

サブクラスUITabBarController - MyTabBarController

以上viewDid負荷書く:すべてのタブバーの項目についてやストーリーボードでこのセットのよう

書き込み

UITabBarItem *tabBarItem0 = [self.tabBar.items objectAtIndex:0]; 
    [tabBarItem0 setFinishedSelectedImage:[UIImage imageNamed:@"selectedimage.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"image.png"]]; 

MyTabBarControllerにタブバーコントローラを設定します。それは正常に動作しています。

12

- (void)setFinishedSelectedImage:withFinishedUnselectedImage:は推奨されていません。このコードは、あなたのUITabBarControllerサブクラスのviewDidLoadオーバーライドに属していること

var settingsItem = self.tabBar.items?[0] as UITabBarItem 
settingsItem.selectedImage = UIImage(named: "home-selected") 

注:ストーリーボードを使用している場合、それはスウィフトで

EDIT

UITabBarItem *tabBarItem0 = [self.tabBar.items objectAtIndex:0]; UIImage* selectedImage = [[UIImage imageNamed:@"settings-active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tabBarItem0.selectedImage = selectedImage; 

と同じくらい簡単です。

1

これはストーリーボードで簡単に行うことができます。あなたが持っている各tabviewcontroller上には、階層内のタブバー項目が含まれているはずです(小さな青い星のように見えます)。これをクリックすると、右の設定は下の画像のようになります。タブバータイトル&イメージはここで変更できます。 Xcodeの6では

enter image description here

関連する問題