Add a toolbar to the controller (Swift language)

Source: Internet
Author: User

//Lazy loading Tool bar    PrivateLazy var Toolbar:uitoolbar =Uitoolbar ()//set the bottom bar    Privatefunc Settoolbar () {//Adding child controlsView.addsubview (ToolBar)//Add constrainttoolbar.snp_makeconstraints {(make), Voidinchmake.bottom.left.right.equalTo (view) make.height.equalTo ( +)        }                //set toolbar by arrayvar items =[Uibarbuttonitem] ()//Add UibarbuttonitemLet itemsettings = [["ImageName":"compose_toolbar_picture"],["ImageName":"Compose_mentionbutton_background"],            ["ImageName":"Compose_trendbutton_background"],            ["ImageName":"Compose_emoticonbutton_background"],            ["ImageName":"Compose_add_background"]]        //Traverse Itemsettings         forDictinchitemsettings {Let btn=UIButton (type:. Custom) Let ImageName= dict["ImageName"]!//set up a picturebtn.setimage (UIImage (Named:imagename), forstate:. Normal) Btn.setimage (UIImage (Named:imagename+"_highlighted"), Forstate:. Highlighted) let item=Uibarbuttonitem (CUSTOMVIEW:BTN) btn.sizetofit ()//Add item to arrayitems.append (item)//instanced SpringsLet space =Uibarbuttonitem (barbuttonsystemitem:. Flexiblespace, Target:nil, Action:nil) items.append (space)}//remove the last springitems.removelast ()//Add to ToolbarToolbar.items =Items}

Execution Result:

Add a toolbar to the controller (Swift language)

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.