Previous projects have been developed based on OC and have recently begun to attempt to rewrite the entire project using the Swift language.
This article focuses on how to use Swift to implement a common general-purpose app installation boot interface.
Effect preview:
Implementation ideas:
The main use of Uiscrollview as a container, the width of its contentsize set to (Guide page number) * screen width, and set pagingenabled to True, hide the scroll bar. As instructed Uipagecontrol and Uiscrollview are added directly above the Self.view, and save the Uipagecontrol on top.
Implementation code:
ImportUIKitclassYsyguideviewcontroller:uiviewcontroller,uiscrollviewdelegate {var scrollview:uiscrollview!var Pagecontrol:uipagecontrol!var Startbtn:uibutton!override func Viewdidload () {Super. Viewdidload ()//Do any additional setup after loading the view.loadcustomlayout ()} override func didreceivememorywarning () {Super. didreceivememorywarning ()//Dispose of any resources the can be recreated. } //ScrollView Delegatefunc Scrollviewdidscroll (scrollview:uiscrollview) {var offset=Scrollview.contentoffset pagecontrol.currentpage=int (offset.x/yunshouyi.screen_width)if(pagecontrol.currentpage==2) {Startbtn.hidden=false }Else{Startbtn.hidden=true } } //loading a custom layoutfunc loadcustomlayout () {ScrollView=uiscrollview (frame:cgrectmake (0, 0, Yunshouyi.screen_width, Yunshouyi.screen_height)) Scrollview.pagingenabled=trueScrollview.showshorizontalscrollindicator=falseScrollview.showsverticalscrollindicator=falsescrollview.contentsize=cgsizemake (*yunshouyi.screen_width, Yunshouyi.screen_height) forI in 1...4{var image=uiimage (named: "Guideline-\ (i)") var ImageView=Uiimageview (image:image) imageview.frame=cgrectmake (CGFloat (i-1) *yunshouyi.screen_width, 0, Yunshouyi.screen_width, yunshouyi.screen_height) Imageview.contentmode=Uiviewcontentmode.scaletofill Scrollview.addsubview (imageView)} pagecontrol=uipagecontrol (Frame:cgrectmake (yunshouyi.screen_width/2-100, yunshouyi.screen_height-100, 200, 100)) Startbtn=uibutton (Frame:cgrectmake (yunshouyi.screen_width/2-60, yunshouyi.screen_height/2+50, 120, 35)) Pagecontrol.numberofpages=3; Pagecontrol.currentpage=0Startbtn.settitle ("Immediate experience", ForState:UIControlState.Normal) startbtn.setbackgroundimage (UIImage (named:"Startbutton"), ForState:UIControlState.Normal) Startbtn.settitlecolor (Uicolor.whitecolor (), ForState:UIControlState.Norma L) Startbtn.addtarget (Self, Action:"Guideover", forControlEvents:UIControlEvents.TouchUpInside) Startbtn.hidden=truescrollview.bounces=falsescrollview.delegate=Self self.view.addSubview (scrollView) Self.view.addSubview (Pagecontrol) Self.view.addSubview (star TBTN)}//get started with appsfunc guideover () {var mainvc=Uinavigationcontroller (Rootviewcontroller:uitableviewcontroller ()) Self.presentviewcontroller (MainVC, Animated:true, Completion:nil)} Override Func Prefersstatusbarhidden ()-Bool {return true } }
iOS Development Note (Swift)-implementation of the Generic App Installation Guide page