gpt4 book ai didi

iOS8如何设置TabBarItem图片

转载 作者:行者123 更新时间:2023-12-01 16:14:49 26 4
gpt4 key购买 nike

iOS8 似乎发生了一些变化,现在我的标签栏图标都无法正常显示。大多数情况下,它们不会显示,直到选项卡处于事件状态:

enter image description here

但有时他们根本不出现,只给我一个蓝色的大框(就像每当我忽略覆盖整个窗口的 View 时):

enter image description here

这是我在 iOS8 之前所做的:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem1.title = @"";

最佳答案

如前所述,如果您看一下:

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITabBarItem_Class/index.html#//apple_ref/occ/instm/UITabBarItem/setFinishedSelectedImage:withFinishedUnselectedImage :

你会注意到这个方法被弃用了,尝试改变:

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];

到:

[tabBarItem1 setImage:[[UIImage imageNamed:@"paintbrush-white.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"paintbrush-black.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

您可能还会遇到图像大小问题,这取决于在 iPhone 5 屏幕和 iPhone 6 屏幕上测试 @2x 图像时图像的大小

关于iOS8如何设置TabBarItem图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26049021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com