自定义UITabBar中的More UIBarButtonItem [英] Customize the More UIBarButtonItem in UITabBar

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

问题描述

从 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"];
    }

结果如下,没有拾取我自定义的More图片.

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 是只读的,但事实并非如此.所以只需执行以下操作:

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中的More UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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