When using Tabbarcontroller in swift, use the map to add.
Bundle extensions
Import Foundation
extension Bundle {
//computed Type property is similar to function, no parameter, return value
var namespace:string {
return Infodictionary? ["Cfbundlename"] as? String?? ""
}
}
Tabbarcontroller
Import UIKit class Twtabbarcontroller:uitabbarcontroller {override Func Viewdidload () {super.viewdidload ( )//Add sub-controller Setupchildcontrollers ()}} extension Twtabbarcontroller {private Func Setupchildcon Trollers () {//Use map processing let array = [["Clsname": "Homeviewcontroller", "title": "Home", "imgname": "Home"], ["Clsname": "Towviewcontroller", "title": "Message", "Imgname": "Message_center"], ["Clsname": "Th Reeviewcontroller "," title ":" Discovery "," imgname ":" Discover "], [" Clsname ":" Fourviewcontroller "," title ":" I "," Imgnam E ":" Profile "]," var arraym = [Uiviewcontroller] () for dict in array{Arraym.appe ND (Controller (dict:dict))} viewcontrollers = Arraym} private func Controller (DICT:[STRING:STR ing]), Uiviewcontroller {guard Let Clsname = dict["Clsname"], let title = dict["title"], let imgname = dict[" Imgname "], let CLS = NSCLassfromstring (Bundle.main.namespace + "." + Clsname) as? Uiviewcontroller.type else {return Uiviewcontroller ()}//2 CREATE VIEW Controller//1> will Clsna Me converted to CLS let VC = Cls.init () Vc.title = title//3. Set Image vc.tabBarItem.image = UIImage (named: "Tabbar_" + imgname) Vc.tabBarItem.selectedImage = UIImage (named : "Tabbar_" + imgname + "_selected")? Withrenderingmode (. alwaysoriginal)//Set Tabbar title Color//4. Sets the caption font (size) of the Tabbar vc.tabBarItem.setTitleTextAttributes ([NSAttributedStringKey.foregroundColor:UICo Lor.orange], for:. highlighted)//system default is 12th, modify the font size, to set the Normal font size Vc.tabBarItem.setTitleT Extattributes ([NSAttributedStringKey.font:UIFont.systemFont (Ofsize:12)], For:uicontrolstate (RA wvalue:0))//5 When the navigation controller is instantiated, the push method is called to ROOTVC stack let nav = Twnavigationcontroller (rootviewcontroller: VC) return nAV}}