Navigation bar and Tabbar combination of projects, in our usual development will often see, below we through the custom Tabbar to achieve a navigation and tabbar combination of demo.
1. Custom Tabbar
Import UIKitclassgoftabbarcontroller:uitabbarcontroller{Overridefunc viewdidload () {super.viewdidload (); Addtabbarchildviewcontroller (Gofmainviewcontroller (), title:"Home Page", ImageName:"Tab_home", Selectedimagename:"Tab_home_sel", tag:0); Addtabbarchildviewcontroller (Gofdrugviewcontroller (), title:"List of medicines", ImageName:"Tab_drug", Selectedimagename:"Tab_drug_sel", tag:1); Addtabbarchildviewcontroller (Gofshopcartviewcontroller (), title:"Shopping Cart", ImageName:"Tab_shopcart", Selectedimagename:"Tab_shopcart_sel", tag:2); Addtabbarchildviewcontroller (Gofmyviewcontroller (), title:"my own", ImageName:"tab_my", Selectedimagename:"Tab_my_sel", tag:3); } Privatefunc Addtabbarchildviewcontroller (Childvc:uiviewcontroller, title:string, imagename:string, SelectedImageName : String, Tag:int) {Let Vcitem= Uitabbaritem (Title:title, Image:gof_imagewithname (ImageName), Selectedimage:gof_imagewithname (selectedImageName )?. Imagewithrenderingmode (. alwaysoriginal)); Vcitem.tag=tag; Childvc.tabbaritem=Vcitem; Let NAVIGATIONVC=Uinavigationcontroller (ROOTVIEWCONTROLLER:CHILDVC); Addchildviewcontroller (NAVIGATIONVC); } Overridefunc TabBar (Tabbar:uitabbar, Didselectitem item:uitabbaritem) {Printlog ("didselectindex:\ (Item.tag)"); }}
2. How do I use it?
Let VC = goftabbarcontroller (); Self.window?. Rootviewcontroller = VC;
32. How do I implement Tabbar and Navigation view projects in Swift?