32. How do I implement Tabbar and Navigation view projects in Swift?

Source: Internet
Author: User

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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.