How to add Image On 'more' Button of UITabBarController in iOS 6? [duplicate]

元气小坏坏 提交于 2019-12-10 12:27:46

问题


I know how to add UITabBarController and how it is used, I already done it.

My Problem is that I am not able to add image on 'more' tab of UITabBarController.
I know there are many similar questions as mine but did not help me.
After googling I found that we can't add images on 'More' tab in UITabBarController Because more tab is automatically displayed by UITabBarController when UITabBarItem is more Then 5.
I could find how to change SELECTION COLOR AND TITLE OF 'more' button, But I could not find about 'more' button Image.

So may be I need to customize UITabBarController so, I am also searching for customization of UITabBarController but could not find it.

Please help me on this Issue.


回答1:


More button is automatically generate when tabs are more than 5 in iPhone. So you can't do that. Instead you should make a custom tabbar with the help of UIView and UIButtons.

See how to add UIViewController's view on self.view.

[self addChildViewController:yourViewController];
yourViewController.view.frame = anyFrame;
[self addSubview:yourViewController.view];
[yourViewController didMoveToParentViewController:self];

By this you can add different UIViewController on each button's click. All the best! 

Well If you dont want to create it yourself. Below is the list of custom tabbars find the one which suits your requirement.

  1. AKTabBarController
  2. InfiniTabBar
  3. RaisedCenterTabBar
  4. MHTabBarController
  5. TweetBotTabBar
  6. ALCustomTabBarController
  7. MHCustomTabBarController
  8. M13InfiniteTabBar
  9. TabBarKit
  10. RNSwipeBar
  11. BCTabBarController
  12. TabBarAnimation
  13. ExpandableTabBar
  14. JBTabBarController
  15. JSScrollableTabBar
  16. NGTabBarController
  17. crtabbar
  18. VSTabBar
  19. DMFilterView
  20. CubeTabBarController
  21. FSVerticalTabBarController
  22. PrettyKit



回答2:


You can add an image for each item , for the selected and unselected states. Like this:

UIImage *selectedImage0     = [UIImage imageNamed:@"image1.png"];
UIImage *unselectedImage0   = [UIImage imageNamed:@"image1_unselected.png"];

UIImage *selectedImage1     = [UIImage imageNamed:@"image2.png"];
UIImage *unselectedImage1   = [UIImage imageNamed:@"image2_unselected.png"];

UIImage *selectedImage2     = [UIImage imageNamed:@"image3.png"];
UIImage *unselectedImage2   = [UIImage imageNamed:@"image3_unselected.png"];

UIImage *selectedImage3     = [UIImage imageNamed:@"image4.png"];
UIImage *unselectedImage3   = [UIImage imageNamed:@"image4_unselected.png"];

UIImage *selectedImage4     = [UIImage imageNamed:@"image5.png"];
UIImage *unselectedImage4   = [UIImage imageNamed:@"image5_unselected.png"];

UITabBar     *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0  = [tabBar.items objectAtIndex:0];
UITabBarItem *item1  = [tabBar.items objectAtIndex:1];
UITabBarItem *item2  = [tabBar.items objectAtIndex:2];
UITabBarItem *item3  = [tabBar.items objectAtIndex:3];
UITabBarItem *item4  = [tabBar.items objectAtIndex:4];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];

You can place this code in the viewDidLoad method of any of your controllers.

Hope it works for you thanks!




回答3:


Try to create more than 5 segues from TabBarController to others and than you will see more button. Add images on the TabBar item of each controller you were connected and you will see this tabbar item's icon on the main TabBar



来源:https://stackoverflow.com/questions/17311489/how-to-add-image-on-more-button-of-uitabbarcontroller-in-ios-6

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