美文网首页
Swift仿新浪项目一:启动

Swift仿新浪项目一:启动

作者: Mr姜饼 | 来源:发表于2019-12-25 17:57 被阅读0次

项目的结构目录


image.png

项目开始


ViewController.swift

修改继承的基类

import UIKit

class ViewController: WBMainViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }

}

WBMainViewController.swift
//
//  WBMainViewController.swift
//  SinoDemo
//
//  Created by jiangbin on 2019/12/25.
//  Copyright © 2019 ice. All rights reserved.
//

import UIKit

class WBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        setupChildControllers()
    }
    
}

extension WBMainViewController{

    private func setupChildControllers () {
        
        let arr = [
            ["clsName" : "WBHomeViewController" ,"title" : "首页" , "imageName" : "zzz"]
        ]
        
        var arrM = [UIViewController]()
        
        for dict in arr{
            
            let vc = childController(dict: dict)
            
            arrM.append(vc)
            
        }
        
        viewControllers = arrM
        
=    }
    
    private func childController (dict : [String : String]) -> UIViewController {
        
        guard   let clsName = dict["clsName"] ,
                let title = dict["title"],
                let imageName = dict["imageName"],
                let cls  =  NSClassFromString(Bundle.main.namespace + "." + clsName) as? UIViewController.Type
        else {
            return UIViewController()
        }
        
        let vc = cls.init()
        
        vc.title = title
        
        vc.tabBarItem.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        let nav = WBNavigationViewController(rootViewController: vc)
        
        return nav
        
        
    }
}

相关文章

网友评论

      本文标题:Swift仿新浪项目一:启动

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