[Swift Learning] The use of the Uisegsmentedcontrol of Uikit

Source: Internet
Author: User
Tags uikit

Creation of UIButton:

(1) using Ctrl+drag drag-and-drop method in Stroyboard to create

(2) Code creation: Uisegsmentedcontrol


"Swift Code"     override func viewdidload ()  {         super.viewdidload ()         // Do any  Additional setup after loading the view, typically from a nib.                 //Setting the contents of an option         let segitems = ["Headlines", "Technology", "Finance", "History"];         //Initialize tab control (segmented selection control)          Let segmentmenu:uisegmentedcontrol = uisegmentedcontrol (Items: segitems);                 segmentmenu.center =  self.view.center;                 segmentmenu.selectedsegmentindex = 0; //default selection of the first option                  //Add Event         segmentmenu.addtarget (self ,            action:  "segmentDidChanged:",             forControlEvents:  uicontrolevents.valuechanged );                 //Add a child view         self.view.addsubview ( Segmentmenu);    }        func  Segmentdidchanged (Segmentmenu:uisegmentedcontrol) {        //Gets the index of the option         print (Segmentmenu.selectedsegmentindex)          //Get the selected text     &NBSp;   print (Segmentmenu.titleforsegmentatindex (segmentmenu.selectedsegmentindex)!)                 //Modifying the color of a control         segmentmenu.tintcolor=uicolor.greencolor ()          //Modify the background color of the control         // Segmentmenu.backgroundcolor = uicolor.graycolor ()              }



Operating environment: Xcode Version 7.0 (7a220)

Resources:

Http://www.hangge.com/blog/cache/detail_533.html

Http://www.cnblogs.com/li--nan/p/4506826.html



[Swift Learning] The use of the Uisegsmentedcontrol of Uikit

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.