Swift UI special training 38 using code to implement the scroll screen ScrollView

Source: Internet
Author: User

Sometimes we can not put all the content in a page, we need to use the ScrollView, the extra content is scroll to get.

First define the width and height, easy to fit the equipment.

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, vertical scrollbar, and top button are displayed. Let's set it to true to see the effect, and don't forget to show this scrollview to the page:

Self.view.addSubview (ScrollView)

Then we add the required content to this scrollview, for example by 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)

Run a look at the effect

Because we set the size of the ScrollView to 800 higher than the screen height, we drag down and note the scroll bar that appears on the right:

Then continue adding what you need.

Swift UI special training 38 using code to implement the scroll screen 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.