iOS 遍历tabbar所有控件

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("...")

                                        }

                                    }

                                }

                            }



                    }

                }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容