ios 为 iPhone 应用程序创建自定义 UITabBar 真的很酷吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4640588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:28:43  来源:igfitidea点击:

Really cool way to create custom UITabBar for iPhone app?

iphoneioscustomizationuitabbaruitabbaritem

提问by zanona

I am doing a lot of researching lately about how to get a different looking with nice effects UITabBaron my iPhone app, but unfortunately I am only finding things on how to replace background color etc.

我最近做了很多关于如何UITabBar在我的 iPhone 应用程序上获得不同外观和良好效果的研究,但不幸的是我只找到关于如何替换背景颜色等的东西。

Well, I've checked out this app called Momentowhich is pretty cool and presents a very slick tabBar:

好吧,我已经检查了这个名为Momento 的应用程序,它非常酷,并提供了一个非常漂亮的 tabBar:

Momento's UITabBar

Momento 的 UITabBar

So there are a couple of elements here I would like to ask you guys if you could help me by giving me the right directions on how to get a similar effect :)

所以这里有几个要素,我想问你们是否可以通过为我提供有关如何获得类似效果的正确方向来帮助我:)

  • Arrow above items:as you can see this app has this animated arrow that runs above the selected item with a very smooth animation.

  • Selected Stated of the item's imageis not that blue-ishdefault one neither the default state which displays in a different shade of brown and gray version.

  • nice Items separatorswith beveled vertical lines.

  • different background imagefor the tabBar

  • different heightfor the tabBar

  • 项目上方的箭头:正如您所看到的,这个应用程序有一个动画箭头,它以非常流畅的动画运行在所选项目上方。

  • 选定规定的项目的形象是不是蓝光ISH默认一个既不是默认状态,这表现在以不同的色调的棕色和灰色版本。

  • 带有斜角垂直线的漂亮项目分隔符

  • tabBar 的不同背景图像

  • tabBar 的不同高度

At this point after some research I am able to set the height and background image by subclassing UITabBarControllerbut I'm still not sure on how to accomplish the other items specially the first one related to the nice arrow effect.

在这一点上,经过一些研究,我可以通过子类化来设置高度和背景图像,UITabBarController但我仍然不确定如何完成其​​他项目,特别是与漂亮箭头效果相关的第一个项目。

How do I do this? Please clarify what can or can't be done by subclassing the UITabBarControllerand specially if can be done in Interface Builder.

我该怎么做呢?请通过子类化UITabBarController和特别说明在 Interface Builder 中可以做什么或不能做什么。

回答by Dave DeLong

There's a project on github called BCTabBarControllerthat aims to mimic the tab bar used in Twitter for iPhone. It's got some of the things you're looking for, and should give a great starting point.

github 上有一个项目BCTabBarController,旨在模仿 iPhone 版 Twitter 中使用的标签栏。它有一些你正在寻找的东西,应该提供一个很好的起点。

回答by esilver

Both of these are good answers, but both libraries have problems: BCTabBarController doesn't know how to create the "blue" highlighted version of a tab bar icon; and iDevRecipies doesn't send events to child viewcontrollers nor resize the navigation bar on rotate.

这两个都是很好的答案,但两个库都有问题: BCTabBarController 不知道如何创建标签栏图标的“蓝色”突出显示版本;并且 iDevRecipies 不会向子视图控制器发送事件,也不会在旋转时调整导航栏的大小。

Be warned: custom nav bars are a lot of trial-and-error debugging (as I have found).

请注意:自定义导航栏需要进行大量试错调试(如我所见)。

回答by Sreekanth

Simply use a UIView with TabBar width and height.Add custom background image and custom buttons on the view.Set the fileowner of the view as AppDelegate.Now you can simply connect the IBActions with the buttons.The Custom view can be placed over the tabbar by addSubView to the TabBar controller's view.You can switch between viewcontrollers by using the setSelectedIndex method of tableviewcontroller in the button action.

只需使用带有 TabBar 宽度和高度的 UIView。在视图上添加自定义背景图像和自定义按钮。将视图的文件所有者设置为 AppDelegate。现在您可以简单地将 IBActions 与按钮连接起来。自定义视图可以放置在标签栏上通过 addSubView 到 TabBar 控制器的视图。您可以在按钮操作中使用 tableviewcontroller 的 setSelectedIndex 方法在视图控制器之间切换。