Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

ios5 - Customize the More UIBarButtonItem in UITabBar

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.

Inactive more button Ugly active more button

I have seen many hacks to replace the more button but there's got to be a better way of doing this right?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...