-1

選択されていないタブ バーのアイコン イメージのアイコンの色合いを変更しようとしています。以下のパッチコードを使用しましたが、このパッチコードを見つけた投稿には、これをタブバーコントローラーで実行するように書かれていますが、その方法がわからなかったので、-(void)viewDidLoad メソッドで実行しましたビューコントローラー .m ファイル。「タイプ 'ViewController *' のオブジェクトにプロパティ 'tabBar' が見つかりません」というエラーが表示されました。これを修正するにはどうすればよいですか?

// set color of selected icons and text to red
self.tabBar.tintColor = [UIColor redColor];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];


// set color of unselected text to green
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], NSForegroundColorAttributeName, nil]
                                         forState:UIControlStateNormal];

// set selected and unselected icons
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];

// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item0.image = [[UIImage imageNamed:@"unselected-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item0.selectedImage = [UIImage imageNamed:@"selected-icon.png"];
4

2 に答える 2