自定义UITabBarController
我想自定义 UITabBarController 的选项卡栏的外观和感觉。我想更改颜色、选择图标时的外观,而且最重要的是,我想减小自定义工具栏的大小。
我的方法和其中的障碍是:
A)我想到的第一个解决方案是创建我自己的viewController,它将像一个底部有按钮的UITabBarController一样,并将这个viewController添加到窗口中。一旦用户点击底部的按钮,将可视区域中的视图与新的 viewController 交换,该新的 viewController 对应于用户现在点击的按钮。
这种策略的问题是:由于我交换视图,相应的 viewController 将不会收到这些消息:
viewWillAppear
viewWillDisappear
viewDidAppear
viewDidDisappear
以及所有轮换事件
B)我可以在该线程中使用已接受的答案的方法: 自定义 UITabBarController 视图控制器和视图的问题
但是我的 tabBar 的高度与默认值不同。
由于上述原因,我无法使用这些方法。
话虽如此,我对“更多”选项卡没有特殊要求。我将只有 5 个选项卡将由选项卡栏显示,因此选项卡栏项目的重新排序超出了范围。
等待建议和想法。
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) 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.
The problem with this strategy is: since I swap view's the corresponding viewControllers will not get these messages:
viewWillAppear
viewWillDisappear
viewDidAppear
viewDidDisappear
And all the rotation events
B) I could have used the accepted answer's approach in this thread:
Custom UITabBarController Problems with View Controllers and Views
But my tabBar's height is not the same as the default.
Due to the cited reasons above, I cannot use those approaches.
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.
Awaiting suggestions and ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未尝试过这样的事情,但据我所知,您应该手动将这些消息发送到您的子视图控制器。
在适当的时刻将 -viewWill/Did(Dis)Appear 发送到正确的控制器应该没有问题。这也是
UITabBarController
所做的事情。至于旋转事件:
在
shouldAutorotateToInterfaceOrientation:
中,将此消息转发给您的子控制器,并根据它们的返回值设置您的返回值(UITabBarController
仅返回YES
(如果其所有子控制器都针对请求的方向返回YES
)。转发
willRotateToInterfaceOrientation:duration:
、didRotateFromInterfaceOrientation:
和willAnimateRotationToInterfaceOrientation:duration:
到子控制器(至少到当前可见的控制器)如果您已正确设置子控制器视图的自动调整大小蒙版,则当系统旋转自定义选项卡栏控制器视图时,您可以正确旋转并调整它们的大小。 (至少我认为它应该是这样工作的。)
同样,我不确定这是否有效。
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.
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.As for rotation events:
In
shouldAutorotateToInterfaceOrientation:
, forward this message to your child controllers and set your return value depending on their return values (UITabBarController
only returnsYES
if all its child controllers returnYES
for the requested orientation).Forward
willRotateToInterfaceOrientation:duration:
,didRotateFromInterfaceOrientation:
andwillAnimateRotationToInterfaceOrientation: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.
您可以使用 CGRect make 实现以下代码来创建自定义选项卡栏,该代码用于创建自定义选项卡栏。进一步的代码用于创建自定义选项卡栏
You can implement the following code for the creating the custom tab bar in that use to images using the CGRect make.further code is use for the creating the custom tab bar