jkpang / PPBadgeView

iOS Custom Badge, Support UIView, UITabBarItem, UIBarButtonItem ,Support Objective-C/Swift; iOS自定义Badge组件, 支持UIView, UITabBarItem, UIBarButtonItem, 支持Objective-C/Swift
MIT License
848 stars 119 forks source link

UITabBarItem+PPBadgeView not work in iOS 14 #50

Open AppLog opened 3 years ago

AppLog commented 3 years ago

In iOS 14, can not add a badge view in UITabBarItem. Debug the code ,we can see that :

- (UIView *)bottomView
{
    // 通过Xcode视图调试工具找到UITabBarItem原生Badge所在父视图
    UIView *tabBarButton = [self valueForKey:@"_view"];
    for (UIView *subView in tabBarButton.subviews) {
        if (subView.superclass == NSClassFromString(@"UIImageView")) {
            return subView;
        }
    }
    return tabBarButton;
}

The line code [self valueForKey:@"_view"] return nil. Can not get a view as container for badge view.

AppLog commented 3 years ago

After debug activity, I found that after the UITabBarController had finished initial and start working ,then we can add badge view.