xcode 带有自定义标题颜色和图像的 UITabBarItem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6051706/
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
UITabBarItem with custom title color and images
提问by Arthur Neves
I`m trying to customize my TabBar in xcode,ios, however I just found ppl saying that this is not customizable! also, i did find some sort of solutions, but none of them are working for me.
我正在尝试在 xcode,ios 中自定义我的 TabBar,但是我刚刚发现 ppl 说这不可自定义!此外,我确实找到了某种解决方案,但没有一个对我有用。
Pretty much I want to change the UITabBarItem title(text) color, and also change the 2 images inside it, the normal one and the selected one!
我几乎想更改 UITabBarItem 标题(文本)颜色,并更改其中的 2 个图像,普通图像和选定图像!
I tried to iterate inside my UITabBar subviews to see if I find something, but any success:
我试图在我的 UITabBar 子视图中迭代,看看我是否找到了一些东西,但是否成功:
for (UIView *view in [self.tabBarController tabBar].subviews)
{
NSLog(@"Class: %@",[view class]);
}
the output of this was:
这个的输出是:
2011-05-18 18:15:24.031 EventApp[52235:207] Class: UIImageView
2011-05-18 18:15:24.032 EventApp[52235:207] Class: UITabBarButton
2011-05-18 18:15:24.032 EventApp[52235:207] Class: UITabBarButton
2011-05-18 18:15:24.033 EventApp[52235:207] Class: UITabBarButton
2011-05-18 18:15:24.033 EventApp[52235:207] Class: UITabBarButton
2011-05-18 18:15:24.034 EventApp[52235:207] Class: UITabBarButton
and I cannot import that UITabBarButton obj to work with it!
而且我无法导入该 UITabBarButton obj 来使用它!
Some solution for that?! also I posted some links bellow which I`ve looked, but didnt work!
一些解决方案?!我还发布了一些我看过的链接,但没有用!
Custom UITabBarItem Image/Title on iPhone
iPhone 上的自定义 UITabBarItem 图片/标题
changing text color of uitabbaritem
EDITWhat I wanna do is somethink like the follow:
编辑我想做的是像下面这样的想法:
回答by luvieere
In iOS 5.0 and newer, you can Customize UITabBar's Appearanceby changing the tint color, the background image and the selection indicator, to make them look the way you like.
在 iOS 5.0 及更新版本中,您可以通过更改色调颜色、背景图像和选择指示器来自定义 UITabBar 的外观,使其看起来像您喜欢的那样。
You can also customize the individual UITabBarItems, by invoking the setFinishedSelectedImage:withFinishedUnselectedImage:method with finished selected and unselected images as parameters.
您还可以通过调用setFinishedSelectedImage:withFinishedUnselectedImage:方法将已完成的选择和未选择的图像作为参数来自定义各个 UITabBarItems 。
Alternatively, modifying the appearance proxyof UITabBar allows you to change the aspect of all its instances.
回答by Henrik P. Hessel
And I'm one of the people that says that it really doesn't work. You have to reimplement the whole functionality in a Custom UIViewController which acts as a UITabBar replacement.
我是说这真的行不通的人之一。您必须在用作 UITabBar 替代品的自定义 UIViewController 中重新实现整个功能。
Just like Twitter for iPhone or Tweetbot did.
就像 iPhone 版 Twitter 或 Tweetbot 所做的一样。
回答by Joris Kluivers
Totally not customizable. You either use whatever Apple provided to you (mask images for shapes and titles) or you roll your own.
完全不能定制。你要么使用 Apple 提供给你的任何东西(形状和标题的蒙版图像),要么你自己动手。
One way that has worked for me is subclassing the tab bar. Use your own subviews to make the tab bar look they way you want it to. For example: use a background image and dynamically overlay that with buttons for each of the tabBarItems.
对我有用的一种方法是对标签栏进行子类化。使用您自己的子视图使标签栏看起来像您想要的那样。例如:使用背景图像并动态覆盖每个 tabBarItems 的按钮。
This way you can still configure the tab bar in Interface Builder and you get the switching of the tab bar content for free. At the same time the tab bar will look the way you want.
这样您仍然可以在 Interface Builder 中配置标签栏,并且您可以免费获得标签栏内容的切换。同时,标签栏将按照您想要的方式显示。