How to add small red dot in UITabBarItem

后端 未结 10 2339
一整个雨季
一整个雨季 2020-12-13 02:44

How to add red dot on the top right side of the UITabBarItem. \"enter

I h

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 03:36

    i test this question's answer. but not work on iPad. now i found that, when u add this on iPhone, tabBarItem left and right margin is 2, and each items margin is 4. Code as below:

        NSInteger barItemCount = self.tabBar.items.count;
    
        UITabBarItem *barItem = (UITabBarItem *)self.tabBar.items[index];
        CGFloat imageHalfWidth = barItem.image.size.width / 2.0;
    
        CGFloat barItemWidth = (BXS_WINDOW_WIDTH - barItemCount * 4) / barItemCount;
        CGFloat barItemMargin = 4;
        CGFloat redDotXOffset = barItemMargin / 2 + barItemMargin * index + barItemWidth * (index + 0.5);
    

    and iPad as below:

        barItemWidth = 76;
        barItemMargin = 34;
        redDotXOffset = (BXS_WINDOW_WIDTH - 76 * barItemCount - 34 * (barItemCount - 1)) / 2.0 + 76 * (index + 0.5) + 34 * index;
    

    Hope this is useful.

提交回复
热议问题