Customize the More UIBarButtonItem in UITabBar

喜欢而已 提交于 2019-12-17 19:56:01

问题


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?


回答1:


The solution was silly.

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.



来源:https://stackoverflow.com/questions/12150788/customize-the-more-uibarbuttonitem-in-uitabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!