Tab Bar with Large Icons

前端 未结 3 609
清歌不尽
清歌不尽 2021-01-03 16:40

I am wondering if there is a way to accomplish a tab bar with only large icons, I have attached an image below for reference. I am not interested in creating my own tab bar

3条回答
  •  难免孤独
    2021-01-03 16:51

    Here is my solution, i created a class which is a subclass of UITabBarController.

    CustomTabBarController.h

    @interface CustomTabBarController : UITabBarController
    @property (strong, nonatomic) IBOutlet UITabBar *tabBar;
    @end
    

    CustomTabBarController.m

    - (void)viewDidLoad
    {
        CGRect tabBarFrame = self.tabBar.frame ;
        tabBarFrame.origin.y -= kOrigin;
        tabBarFrame.size.height = kTabBarHeight;
        self.tabBar.frame = tabBarFrame;
        self.tabBarController.delegate = self;
        /* Tab Bar Background */
    
        UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"tabBarBackgroundImage.png"];
        [[UITabBar appearance] setBackgroundImage:tabBarBackgroundImage];
    
        /* Tab Bar Item */
        UIButton *surveyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [surveyButton addTarget:self action:@selector(surveyButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
        surveyButton.tag = surveyButtonTag;
        [surveyButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
        CGRect surveyButtonFrame = surveyButton.frame ;
        surveyButtonFrame.origin.x = /*Proper value in your case */;
        surveyButtonFrame.origin.y = /*Proper value in your case */;
        surveyButtonFrame.size.height = /*Proper value in your case */ ;
        surveyButtonFrame.size.width =/*Proper value in your case */;
        surveyButton.frame = surveyButtonFrame;
        [self.tabBar addSubview:surveyButton];
    
        UIButton *statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
        statusButton.tag = statusButtonTag;
        [statusButton addTarget:self action:@selector(statusButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
        [statusButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
        CGRect statusButtonFrame = statusButton.frame ;
        statusButtonFrame.origin.x = /*Proper value in your case */;
        statusButtonFrame.origin.y = /*Proper value in your case */;
        statusButtonFrame.size.height = /*Proper value in your case */;
        statusButtonFrame.size.width = /*Proper value in your case */;
        statusButton.frame = statusButtonFrame;
        [self.tabBar addSubview:statusButton];
    }
    
    -(void)surveyButtonDidSelect
    {
        self.selectedIndex = 0 ;
    }
    -(void)statusButtonDidSelect
    {
        self.selectedIndex = 1;
    }
    

    It's working for me,and i got no problem. Hope, it helps.

提交回复
热议问题