I don't know if there is a best way to do this, but I will share my experience:
I created my own version of a tab bar by subclassing UIView as opposed to UITabBar. As the linked question mentions, Apple's UI classes are quite finicky about their sizing and I do not think I could get the UITabBar subclass to size as I wanted.
Because I did not have a subclass of UITabBar I also ended up rolling my own versions of UITabBarController and UITabBarDelegate, with interfaces that are essentially the same as the Apple classes. I WAS able to use UITabBarItem to store the title and icon for the buttons on the tab bar, which is useful since UIViewControllers have a tabBarItem property. That lets you store just an array of UIViewControllers in your controller, as opposed to arrays for both controllers and tab bar items.
Because I was using mostly custom classes I did this all programmatically, including creating, configuring and laying out the buttons on the tab bar.
Like I said, this is just my experience, hope it helps.
I did this recently in an application. There was so little "code" to it that there is barely anything to post. I did it as such:
Created a UIImageView (about 50 px high), and laid it out at the bottom of the screen. I filled it with a tab-bar look-alike image - i.e. some sort of grey gradient. I probably subclassed UIImageView - but you don't even have to do that.
I drew a bunch of buttons/icons - 37x37 each.
I placed a bunch of UIButtons in the "tab bar" - and made them "Custom" views, with the buttons/icons I had created.
I simply used the touchUpInside methods to make them do stuff.
When I needed to get fancy - I'd attach the buttons to my code via and IBOutlet, so I could "disable" them - and I'd draw a greyish "disabled state" image for them.
If you want the same functionality, I'd recommend using a UITabBarController, hide the tab bar itself, and then create your own navigation. I've done this a few times and it works quite nicely.
Use something like this to hide your tab bar and expand the content view.
发布评论
评论(4)
我不知道是否有最好的方法来做到这一点,但我将分享我的经验:
我通过子类化 UIView 而不是 UITabBar 创建了我自己的选项卡栏版本。正如链接的问题所提到的,Apple 的 UI 类对其大小非常挑剔,我认为我无法将 UITabBar 子类设置为我想要的大小。
因为我没有 UITabBar 的子类,所以我最终也推出了自己版本的 UITabBarController 和 UITabBarDelegate,其接口本质上与 Apple 类相同。我能够使用 UITabBarItem 来存储选项卡栏上按钮的标题和图标,这很有用,因为 UIViewControllers 有一个 tabBarItem 属性。这使您可以在控制器中仅存储 UIViewController 数组,而不是同时存储控制器和选项卡栏项目的数组。
因为我主要使用自定义类,所以我以编程方式完成了这一切,包括创建、配置和布置选项卡栏上的按钮。
正如我所说,这只是我的经验,希望对您有所帮助。
I don't know if there is a best way to do this, but I will share my experience:
I created my own version of a tab bar by subclassing UIView as opposed to UITabBar. As the linked question mentions, Apple's UI classes are quite finicky about their sizing and I do not think I could get the UITabBar subclass to size as I wanted.
Because I did not have a subclass of UITabBar I also ended up rolling my own versions of UITabBarController and UITabBarDelegate, with interfaces that are essentially the same as the Apple classes. I WAS able to use UITabBarItem to store the title and icon for the buttons on the tab bar, which is useful since UIViewControllers have a tabBarItem property. That lets you store just an array of UIViewControllers in your controller, as opposed to arrays for both controllers and tab bar items.
Because I was using mostly custom classes I did this all programmatically, including creating, configuring and laying out the buttons on the tab bar.
Like I said, this is just my experience, hope it helps.
我最近在一个应用程序中这样做了。它的“代码”太少了,几乎没有什么可发布的。我是这样做的:
创建了一个 UIImageView(大约 50 px 高),并将其放置在屏幕底部。我用标签栏相似的图像填充它 - 即某种灰色渐变。我可能对 UIImageView 进行了子类化 - 但你甚至不必这样做。
我画了一堆按钮/图标 - 每个 37x37。
我在“选项卡栏”中放置了一堆 UIButton,并使用我创建的按钮/图标将它们设为“自定义”视图。
我只是使用 touchUpInside 方法让它们做一些事情。
当我需要变得更奇特时 - 我会通过 IBOutlet 将按钮附加到我的代码,这样我就可以“禁用”它们 - 并且我会为它们绘制一个灰色的“禁用状态”图像。
I did this recently in an application. There was so little "code" to it that there is barely anything to post. I did it as such:
Created a UIImageView (about 50 px high), and laid it out at the bottom of the screen. I filled it with a tab-bar look-alike image - i.e. some sort of grey gradient. I probably subclassed UIImageView - but you don't even have to do that.
I drew a bunch of buttons/icons - 37x37 each.
I placed a bunch of UIButtons in the "tab bar" - and made them "Custom" views, with the buttons/icons I had created.
I simply used the touchUpInside methods to make them do stuff.
When I needed to get fancy - I'd attach the buttons to my code via and IBOutlet, so I could "disable" them - and I'd draw a greyish "disabled state" image for them.
如果您想要相同的功能,我建议使用 UITabBarController,隐藏选项卡栏本身,然后创建您自己的导航。我已经这样做过几次并且效果非常好。
使用类似的方法来隐藏选项卡栏并展开内容视图。
然后使用 UIButtons 进行自己的导航以在视图控制器之间切换。
[tabBarController_ setSelectedIndex:0];
If you want the same functionality, I'd recommend using a UITabBarController, hide the tab bar itself, and then create your own navigation. I've done this a few times and it works quite nicely.
Use something like this to hide your tab bar and expand the content view.
Then make your own navigation with UIButtons to switch between your view controllers.
[tabBarController_ setSelectedIndex:0];
我认为这就是您正在寻找的......应该很容易对其进行子类化。欢呼吧!
http://www.rumexit.co.uk/2010/07/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-1- of-2/
I think this is what you are looking for... should be pretty easy to subclass it. gl and cheer!
http://www.rumexit.co.uk/2010/07/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-1-of-2/