美文网首页
iOS 遍历tabbar所有控件

iOS 遍历tabbar所有控件

作者: 流老湿 | 来源:发表于2023-11-26 15:30 被阅读0次

let tabBarVC: TabBarController = UIApplication.shared.keyWindow?.rootViewController as! TabBarController

        //        2.遍历取出所有的 tabBarButton

                fortempViewintabBarVC.tabBar.subviews{

                    iftempView.isKind(of:NSClassFromString("UITabBarButton")!) {

                        //2.1 继续遍历tabBarButton 找到 UITabBarSwappableImageView 并保存

            //                print("tempView : \(tempView.subviews)" )

                            //从subviews中查找

                            fortempImgVintempView.subviews{

                                //第一种层级关系 UITabBarButton --> UITabBarSwappableImageView

                                iftempImgV.isKind(of:NSClassFromString("UITabBarSwappableImageView")!) {

//                                    tabBarSwappableImageViews.append(tempImgV as! UIImageView)

                                    print("...")

                                }else{

                                    //第二种:UITabBarButton --> UIVisualEffectView --> _UIVisualEffectContentView--> UITabBarSwappableImageView

                                     letarray = tempView.subviews[0].subviews[0].subviews

                                    fortempImginarray {

                                        iftempImg.isKind(of:NSClassFromString("UITabBarSwappableImageView")!) {

//                                            tabBarSwappableImageViews.append(tempImg as! UIImageView)

                                            print("...")

                                        }

                                    }

                                }

                            }

                    }

                }

相关文章

网友评论

      本文标题:iOS 遍历tabbar所有控件

      本文链接:https://www.haomeiwen.com/subject/bwmawdtx.html