Swift UI special training 38 with scroll code ScrollView

Source: Internet
Author: User

Sometimes we fit the entire content of the page, we need to use ScrollView, additional content to get through scrolling.

What kind of width and height first, definition, fitness equipment easy.

Let PageWidth =    PageHeight = 800

Then initialize a scrollview in the viewdidload:

var ScrollView = Uiscrollview ()        scrollview.frame = Self.view.bounds                scrollview.contentsize=cgsizemake ( CGFloat (PageWidth), CGFloat (pageheight))        scrollview.pagingenabled = True        Scrollview.showshorizontalscrollindicator = True        Scrollview.showsverticalscrollindicator = True        Scrollview.scrollstotop = True

To implement the scrolling, the pagingenabled must be set to true.

The remaining properties correspond to whether the horizontal scroll bar is displayed, the vertical scroll bar, and the button that returns to the top. Let's set it to true first to see the effect. Don't forget to show this scrollview to the page:

Self.view.addSubview (ScrollView)

Then we add the required content to this scrollview, such as adding a caption:

var Label1 = UILabel (Frame:cgrectmake (+, +))        Label1.Text = "Cabbage in memory"        Label1.textcolor = Uicolor.ora Ngecolor ()        Label1.font = uifont.systemfontofsize (23°c)        Scrollview.addsubview (Label1)

Take a look at the effect



As we set the size of the ScrollView to 800 higher than the screen height, we drag downward. Note the scroll bar that appears on the right side:


The need to continue adding content is available.

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Swift UI special training 38 with scroll code ScrollView

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.