Swift Little Exercise-Guide page

Source: Internet
Author: User

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

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.