简体   繁体   English

自定义标签栏iOS-3个按钮

[英]Custom Tab Bar iOS - 3 Buttons

I'm wanting to create a custom tab bar design with only 3 buttons. 我想创建一个只有3个按钮的自定义标签栏设计。 The issue comes when trying to split the images to fit on the iPhones screen. 尝试将图像拆分为适合iPhone屏幕时出现问题。 With the width being 320, you need 2 tabs to be 106 wide and the 3rd to be 108. When I create the images at the right size, they don't fit and I end up with a 1px line down the right hand side like this: 宽度为320时,您需要将2个标签页的宽度设为106,将第三个标签页的宽度设为108。当我以正确的尺寸创建图像时,它们不适合显示,最后我在右侧向下画了1px的线这个:

在此处输入图片说明

This is the code I'm using: 这是我正在使用的代码:

UIImage *selectedImage0 = [UIImage imageNamed:@"tb_1_down.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tb_1_up.png"];

UIImage *selectedImage1 = [UIImage imageNamed:@"tb_2_down.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tb_2_up.png"];

UIImage *selectedImage2 = [UIImage imageNamed:@"tb_3_down.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tb_3_up.png"];

UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];

self.tabBarController.tabBar.frame = CGRectMake(0, 430, 320, 50);

[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tb_tabBar_BG.png"]];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];

Is there any way to make 'item1' 108 wide instead of 106?! 有什么方法可以使'item1'的宽度变为108而不是106?

This might give you what you want: Setting a background image for a tabbar 这可能会给您您想要的东西: 设置选项卡的背景图像

This has process to make fully custom tab bar buttons. 这具有制作完全自定义标签栏按钮的过程。

我担心您可能正在研究UITabBar / UITabBarController的100%自定义实现-我不知道有什么方法可以在这种程度上自定义股票。

I managed to fix this issue by subclassing the UITabBarController, and using UIImageViews instead of UIButtons as @human suggested, as I couldn't get rid of the irrational way of changing the buttons image, which flickered and highlighted irregardless of whether you set an image or not. 我设法通过子类化UITabBarController并使用UIImageViews而不是@human建议的UIButtons来解决此问题,因为我无法摆脱更改按钮图像的不合理方法,无论您是否设置图像,该方法都会闪烁并突出显示或不。

My code can be found in the answer here: UITabBar customisation not working as expected 我的代码可以在这里的答案中找到: UITabBar定制未按预期工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM