2018-06-12

swift 创建TabbarController

先上个图:

首先: 使用代码 创建页面,没有使用nib 文件:


在AppDelegate 中:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {        // Override point for customization after application launch.               

 window = UIWindow(frame: UIScreen.main.bounds)        window?.rootViewController = TabBarController()        window?.backgroundColor = UIColor.white        window?.makeKeyAndVisible()                return true    }

然后新建 tabbarController 类:

funccreatSubTabbarController() -> () {

        lethomepageVC =HomePageController()

        homepageVC.title="首页"


        letcarefulChoseVC =CarefulChoseController()

        carefulChoseVC.title="精选"


        letmineVc =MinePageController()

        mineVc.title="我的"


        letmoreVc =MoreController()

        moreVc.title="更多"


        letvcControllers = [homepageVC,carefulChoseVC,mineVc,moreVc]

        lettabbarTitle = ["首页","理财专区","我的","更多"]

        lettabbarImages = ["首页","理财专区","我的","更多"]

        letselectTabbarImages = ["首页_h","理财专区_h","我的_h","更多_h"]


        vartabControllers :[UINavigationController] = []



        for(index,value)invcControllers.enumerated() {

            lettitle:String= tabbarTitle[index]

            letimage:String= tabbarImages[index]

            letselectImage:String= selectTabbarImages[index]


            letnav =UINavigationController.init(rootViewController: value)

            nav.tabBarItem.title= title

            nav.tabBarItem.image=UIImage.init(named: image)

            nav.tabBarItem.selectedImage=UIImage.init(named: selectImage)

            value.navigationController?.isNavigationBarHidden = true

            tabControllers.append(nav)

        }

        viewControllers= tabControllers

    }

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

推荐阅读更多精彩内容