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