1 Import UIKit2 3 classViewcontroller:uiviewcontroller, Uipageviewcontrollerdelegate, Uipageviewcontrollerdatasource {4 5@IBOutlet weak var redbtn:uibutton!6@IBOutlet weak var yellowbtn:uibutton!7@IBOutlet weak var bluebtn:uibutton!8 9var Vcarr =Nsmutablearray.init ()Tenvar pagevc:uipageviewcontroller! One var currentindex:int { A Get { - ifredbtn.isselected { - returnRedbtn.tag the}Else ifyellowbtn.isselected { - returnYellowbtn.tag -}Else ifbluebtn.isselected { - returnBluebtn.tag +}Else { - return 0 + } A } at - Set { - ifNewValue = =0 { -redbtn.isselected =true -yellowbtn.isselected =false -bluebtn.isselected =false in}Else ifNewValue = =1 { -redbtn.isselected =false toyellowbtn.isselected =true +bluebtn.isselected =false -}Else ifNewValue = =2 { theredbtn.isselected =false *yellowbtn.isselected =false $bluebtn.isselected =truePanax Notoginseng } - } the } + A the Overridefunc viewdidload () { + super.viewdidload () - //additional setup after loading the view, typically from a nib. $ $Let SB = Uistoryboard.init (name:"Main", Bundle:nil) - - forTempidinch["Redviewcontroller","Yellowviewcontroller","Blueviewcontroller"] { theLet TEMPVC =Sb.instantiateviewcontroller (withidentifier:tempid) - Vcarr.add (TEMPVC)Wuyi } the -PAGEVC = Self.childViewControllers.first as! uipageviewcontroller! WuPagevc.Delegate= Self -Pagevc.datasource = Self AboutPagevc.setviewcontrollers ([Vcarr.Object(at:0) as! Uiviewcontroller], direction:. Forward, Animated:true, Completion:nil) $Currentindex =0 - } - - @IBAction Func handlebtnpressed (_ Sender:uibutton) { A ifCurrentindex! =Sender.tag { +Currentindex =Sender.tag thePagevc.setviewcontrollers ([Vcarr.Object(At:currentindex) as! Uiviewcontroller], direction:. Forward, Animated:false, Completion:nil) - } $ } the the Overridefunc didreceivememorywarning () { the super.didreceivememorywarning () the //Dispose of any resources the can be recreated. - } in theFunc Pageviewcontroller (_ Pageviewcontroller:uipageviewcontroller, Viewcontrollerbefore ViewController: Uiviewcontroller, Uiviewcontroller? { theLet index =Vcarr.index (Of:viewcontroller) About ifIndex-1<0 { the returnNil the}Else { the returnVcarr.Object(At:index-1) as?Uiviewcontroller + } - } the BayiFunc Pageviewcontroller (_ Pageviewcontroller:uipageviewcontroller, Viewcontrollerafter ViewController: Uiviewcontroller, Uiviewcontroller? { theLet index =Vcarr.index (Of:viewcontroller) the ifIndex +1>=Vcarr.count { - returnNil -}Else { the returnVcarr.Object(At:index +1) as?Uiviewcontroller the } the } the - Func Pageviewcontroller (_ Pageviewcontroller:uipageviewcontroller, didfinishanimating Finished:bool, PreviousV Iewcontrollers: [Uiviewcontroller], transitioncompleted completed:bool) { theCurrentindex = Vcarr.index (of:pageviewcontroller.viewcontrollers?[0] asAny ) the } the}
Day Nineth: 9_swiftdemo_embedseguewithpageviewcontroller