Any language, as long as there is no need to forget, you have to knock on a small project, practice practiced hand;
Let SCROLLVIEWBG = Uiscrollview.init (frame:slscreenrect)
Let images = ["First", "second", "third"]
Let Pagecontrol = Uipagecontrol.init (Frame:CGRect.init (x:0, y:slscreenheight-30, Width:slscreenwidth, height:20))
var currentpage = 0
Override Var Prefersstatusbarhidden:bool {
return True
}
Override Func Viewdidload () {
Super.viewdidload ()
Additional setup after loading the view, typically from a nib.
Configureview ()
}
Func Configureview () {
Iterate through the array while getting index
For (index, value) in images.enumerated () {
Let ImageView = Uiimageview.init (Frame:CGRect.init (x:cgfloat (index) *slscreenwidth, y:0, width:slscreenwidth, Height: Slscreenheight))
Imageview.image = Uiimage.init (named:value)
Limit boundaries
Imageview.clipstobounds = True
Imageview.contentmode =. Scaleaspectfill
Scrollviewbg. Addsubview (ImageView)
}
Agreement
Scrollviewbg.delegate = Self
Scrollviewbg.ispagingenabled = True
Scrollviewbg.showshorizontalscrollindicator = False
Scrollviewbg.contentsize = Cgsize.init (Width:slscreenwidth*cgfloat (Images.count), height:slscreenheight)
Pagecontol
Pagecontrol.numberofpages = Images.count
Pagecontrol.currentpageindicatortintcolor =. White
Pagecontrol.pageindicatortintcolor =. Lightgray
Pagecontrol.currentpage = CurrentPage
Pagecontrol.isenabled = False
View.addsubview (SCROLLVIEWBG)
View.addsubview (Pagecontrol)
}
MARK:-Protocol method
Func scrollviewdidenddecelerating (_ Scrollview:uiscrollview) {
CurrentPage = Int (scrollview.contentoffset.x/slscreenwidth)
Pagecontrol.currentpage = CurrentPage
}
Swift Little Exercise-Guide page