自定义UITabBarController [英] Custom UITabBarController

查看:101
本文介绍了自定义UITabBarController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义UITabBarController的标签栏的外观和感觉。我想更改颜色,图标在选中时的显示方式,最重要的是,我想减小自定义工具栏的大小。

I want to customize the look and feel of the tab bar of a UITabBarController. I want to change the colors, the way the icon looks when they are selected, and also, most important of all, I want to reduce the size of the custom toolbar.

我的方法和其中的障碍是:

My approaches for this and the hurdles in it are:

A)我想到的第一个解决方案是创建自己的viewController,其行为就像一个UITabBarController按钮,并将此viewController添加到窗口。一旦用户点击底部的按钮,就可以使用新的viewController来交换可见区域中的视图,这对应于用户现在点击的按钮。

A) The first solution which came to my mind was to create my own viewController which will act like a UITabBarController with buttons in the bottom and add this viewController to the window. Once when user taps a button at the bottom, swap the view in the viewable area with the new viewController's which corresponds to the button now tapped by user.

这个问题策略是:因为我交换视图的相应viewController不会得到这些消息:

The problem with this strategy is: since I swap view's the corresponding viewControllers will not get these messages:


  • viewWillAppear

  • viewWillDisappear

  • viewDidAppear

  • viewDidDisappear

  • viewWillAppear
  • viewWillDisappear
  • viewDidAppear
  • viewDidDisappear

和所有轮播事件

B)我可以在这个线程中使用接受的答案:
自定义UITabBarController视图控制器和视图的问题

B) I could have used the accepted answer's approach in this thread: Custom UITabBarController Problems with View Controllers and Views

但是我的tabBar的高度与默认值不一样。

But my tabBar's height is not the same as the default.

由于上述原因,我不能使用这些方法。

Due to the cited reasons above, I cannot use those approaches.

有了这个,我没有特别要求的更多标签。我将只有5个选项卡,将由选项卡栏显示,因此选项卡栏项目的重新排序超出范围。

Having said this, I have no special requirement of More tab. I will be having only 5 tabs which will be displayed by the tab bar and hence the re-ordering of tab bar items is out of scope.

等待建议和想法。

推荐答案

我从来没有尝试这样的,但是我看到它,你应该发送这些消息到你的孩子视图控制器手动。

I have never attempted something like this but as I see it, you are supposed to send those messages to your child view controllers manually.

发送-viewWill / Did(Dis)应该不是问题,在适当的时候出现在正确的控制器上。这是 UITabBarController 的作用。

It shouldn't be problem to send -viewWill/Did(Dis)Appear to the right controller at the appropriate moment. This is what UITabBarController does, too.

旋转事件:


  • shouldAutorotateToInterfaceOrientation:中,将此消息转发给子控制器,并根据返回值设置返回值( UITabBarController 只有 YES 才会返回 YES

  • In shouldAutorotateToInterfaceOrientation:, forward this message to your child controllers and set your return value depending on their return values (UITabBarController only returns YES if all its child controllers return YES for the requested orientation).

前进 willRotateToInterfaceOrientation:duration:当接收到子控制器时,

Forward willRotateToInterfaceOrientation:duration:, didRotateFromInterfaceOrientation: and willAnimateRotationToInterfaceOrientation:duration: to the child controllers (at least to the currently visible one) when you receive them.

如果您已正确设置子控制器视图的自动调整掩码,则在系统旋转自定义选项卡栏控制器视图时,它们会正确旋转和调整大小。 (至少我认为这应该如何工作。)

If you have set the autoresizing masks of your child controllers' views correctly, they you rotate and resize correctly when the system rotates your custom tab bar controller's view. (At least I think that's how it should work.)

再次,我不知道这将工作。

Again, I'm not sure if this will work.

这篇关于自定义UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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