Ios 如何更改选定和未选定选项卡栏图像的颜色

Ios 如何更改选定和未选定选项卡栏图像的颜色,ios,objective-c,uinavigationcontroller,uitabbarcontroller,Ios,Objective C,Uinavigationcontroller,Uitabbarcontroller,我正在尝试更改iOS应用程序中选项卡栏项目的颜色 子视图控制器嵌入在导航控制器中 我在AppDelegate中添加了这段代码,它只改变了文本的颜色 [UITabBarItem.appearance setTitleTextAttributes: @{NSForegroundColorAttributeName : [UIColor colorWithRed:38/255.0 green:54/255.0 blue:73/255.0 alpha:1.0]}

我正在尝试更改iOS应用程序中选项卡栏项目的颜色

子视图控制器嵌入在导航控制器中

我在AppDelegate中添加了这段代码,它只改变了文本的颜色

 [UITabBarItem.appearance setTitleTextAttributes:
 @{NSForegroundColorAttributeName : [UIColor colorWithRed:38/255.0 green:54/255.0 blue:73/255.0 alpha:1.0]}
                                       forState:UIControlStateNormal];

 [UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : kColorTabbarNavigationBarTint}
                                       forState:UIControlStateSelected];
在图像资源中,如果我将特定图像作为原始图像进行渲染,它可以工作,但选择颜色对图像不起作用

请告诉我可以做什么


提前感谢…

尝试下面的代码:当您想以编程方式设置时

// get your TabBarController
//UITabBarController *tabBarController = self.tabBarController
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
UITabBar *tabBar = tabBarController.tabBar;

UITabBarItem *tabItem1 = [tabBar.items objectAtIndex:0];
[tabItem1 setSelectedImage:[UIImage imageNamed:@"selectimg"]];
tabItem1.selectedImage = [[UIImage imageNamed:@"selectimg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem1.image = [[UIImage imageNamed:@"deselectimg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem1.title = @"xxxx";

UITabBarItem *tabItem2 = [tabBar.items objectAtIndex:1];
tabItem2.selectedImage = [[UIImage imageNamed:@"selectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem2.image = [[UIImage imageNamed:@"deselectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem2.title = @"xxxx";

UITabBarItem *tabItem3 = [tabBar.items objectAtIndex:2];
tabItem3.selectedImage = [[UIImage imageNamed:@"selectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem3.image = [[UIImage imageNamed:@"deselectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem3.title = @"xxxx";

UITabBarItem *tabItem4 = [tabBar.items objectAtIndex:3];
tabItem4.selectedImage = [[UIImage imageNamed:@"selectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem4.image = [[UIImage imageNamed:@"deselectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabItem4.title = @"xxxx";
或者,您可以在故事板中进行设置,选择特定的选项卡项并查看下面的内容


您必须为特定选项卡项设置选定图像和未选定图像是的,我在每个viewcontroller类中都尝试过设置,但都不起作用。我们是否应该在序列图像板中为选项卡栏项目设置图像?是的,当然,您可以从序列图像板进行设置。为此,我是否应该在序列图像板的选项卡栏视图控制器中设置图像?还是我应该把这个空着?