如何创建我自己的UITabBar? [英] How can I create my own UITabBar?

查看:114
本文介绍了如何创建我自己的UITabBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了这里这个问题,我真的很有兴趣创建我自己的UITabBar,和滚我自己。我真的很好奇如何做,特别是在一个应用程序,如Twitter应用程序。

Further to this question here, I'm really interested in creating my own UITabBar, and 'rolling my own'. Im really curious as to how this is done, especially in an app such as the Twitter app.

我该怎么做?任何人都可以指出任何好的资源如何子类化?
我应该以编程方式还是在XIB中执行?

How can I do this? Can anyone point to any good resources on how to subclass this? Should I do it programmatically, or in a XIB?

编辑:我正在寻找使用自定义图标/所选图标并仅具有图标。
编辑2:阅读更多答案后,听起来像一个自定义的XXTabBarController是我在这里真正想做的。有人可以评论这个吗?

I'm looking to do this with custom icons/selected icons and having icons only. After reading further answers, it sounds like a custom XXTabBarcontroller is what I actually want to do here. Can anyone comment on this?

谢谢,

推荐答案

不知道是否有最好的方式来执行此操作,但我会分享我的经验:

I don't know if there is a best way to do this, but I will share my experience:

我创建了自己的版本标签栏通过将UIView进行子类化而不是UITabBar。作为链接的问题提到,苹果的UI类对于它们的大小来说是非常有趣的,我不认为我可以根据需要获得UITabBar子类的大小。

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.

因为我没有UITabBar的子类,我也最终滚动了我自己的UITabBarController和UITabBarDelegate版本,其接口与Apple类基本相同。我可以使用UITabBarItem存储标签栏上的按钮的标题和图标,这是有用的,因为UIViewController有一个tabBarItem属性。这样就可以在控制器中存储一个UIViewControllers数组,而不是用于控制器和制表符栏的数组。

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.

这篇关于如何创建我自己的UITabBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆