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