The use of Swift-uisegmentedcontrol

Source: Internet
Author: User

One, create the control, and listen to the control selection value

/*options In addition to the text can also be the image as the keyword function is literally: type conversion*///Let items = ["Option One", "option Two", UIImage (named: "Hgl.jpeg")!] as [Anyobject]Let items = ["Option One","option two"] Let segmented=Uisegmentedcontrol (Items:items)//Segmented.center = Self.view.centerSegmented.frame = CGRectMake ( the,410, Screen_width- the, -) Segmented.selectedsegmentindex=1 //the second item is selected by defaultSegmented.addtarget (Self, Action: #selector (Segmentedclick), forControlEvents:UIControlEvents.ValueChanged)//add value change listenerSelf.view.addSubview (segmented)

Implementation of the method

func Segmentedclick (segmented:uisegmentedcontrol) {                // Gets the index of the option         print ( Segmented.selectedsegmentindex)                // Get the selected text         print ( Segmented.titleforsegmentatindex (Segmented.selectedsegmentindex))            }

Second, the other properties

        //Select Add and remove options in the spaceSegmented.insertsegmentwithtitle ("New Options", Atindex:2, Animated:true)        //Add Picture OptionsSegmented.insertsegmentwithimage (UIImage (named:"Hgl.jpeg"), Atindex:1, Animated:true)        //Removal OptionsSegmented.removesegmentatindex (1, Animated:true)                        //Modify the color of the options (including picture options)Segmented.tintcolor =Uicolor.redcolor ()//Modify Options text/PictureSegmented.settitle ("Swift", Forsegmentatindex:2) Segmented.setimage (UIImage (named:"Hgl.jpeg"), Forsegmentatindex:2)                //Modify Option content offset positionSegmented.setcontentoffset (Cgsizemake (5,3), Forsegmentatindex:2)

The use of Swift-uisegmentedcontrol

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.