我有没有标题和图像只有 UITabBarItem。我想知道我如何能改变图像大小所以它可以占用整个 UITabBarItem。
我找遍整个互联网,但什么也没找到。
我试过:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_Storyboard" bundle:nil];
UITabBarController *tabBarController = [storyBoard instantiateViewControllerWithIdentifier:@"tab"];
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);
但什么都没有改变。
从苹果文档的最大大小的一张图片在 TabBar 是 30 x 30 (60 x 60 的视网膜显示器)。
我不认为它是可能采取整个 TabBar 不拉伸图像的高度。我认为最好的解决办法是中心中使用 imageInset TabBar 的图像
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
否则你可以玩这 imageInset 和拉伸图像像在截图中
tabBarItem1.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
//add image to tabbarItems
tabBarItem1.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);
}