在UITabBar中自定义更多UIBarButtonItem [英] Customize the More UIBarButtonItem in UITabBar
问题描述
自iOS 5以来,Apple提供了一个API来自定义 UITabBar
对象中的 UITabBarItems
。我具体指的是以下选择器:
Since iOS 5 Apple provided an API to customise the UITabBarItems
in the UITabBar
object. I am refering specifically to the following selector:
setFinishedSelectedImage:withFinishedUnselectedImage:
一切都适用于常规按钮,但我似乎无法自定义更多按钮以匹配其他按钮的样式。这就是我在做的事情:
It all works great for regular buttons but I can't seem to customise the "More" button to match the style of the other ones. This is what I am doing:
tabBarController.viewControllers = tabBarControllerArray;
tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
UITabBarItem *more = tabBarController.moreNavigationController.tabBarItem;
if ([more respondsToSelector:@selector(setFinishedSelectedImage:withFinishedUnselectedImage:)]){
[more setFinishedSelectedImage:[UIImage imageNamed:@"BarIcon-More.png"]
withFinishedUnselectedImage:[UIImage imageNamed:@"BarIcon-More.png"]
];
} else {
more.image = [UIImage imageNamed:@"BarIcon-More.png"];
}
结果如下,它不会提取我的自定义更多图片。
The result is as follows, it doesn't pick-up my custom More image.
我见过很多黑客要取代更多的按钮,但必须有更好的方法来做到这一点吗?
I have seen many hacks to replace the more button but there's got to be a better way of doing this right?
推荐答案
解决方案很愚蠢。
我认为 moreNavigationController
中的 UITabBarItems
是readonly而且它不是。所以只需执行以下操作:
I assumed the UITabBarItems
in the moreNavigationController
was readonly and it wasn't. So simply doing the following:
tabBarController.moreNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"More" image:[UIImage imageNamed:@"BarIcon-More.png"] tag:0];
与上述相同的自定义代码有效。
And the same customization code as above works.
这篇关于在UITabBar中自定义更多UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!