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