Thursday, February 21, 2019

Swift Scrollview

We want a view can scroll horizonal and vertical.
Declare one more Scrollview and a Label.
var la:UILabel!
var scrollView: UIScrollView!
Set label width and height lager than the dimension you need. For example, you need 500 width and 800 height, let set label 520, 820 like this.
la = UILabel(frame: CGRect(x: 0, y: 0, width: 520, height: 820))
Add this line for Scrollview.
scrollView = UIScrollView(frame: view.bounds)
After that, put all view like button, image, text in to scrollview.

scrollView.addSubview(tableview)
 scrollView.addSubview(bu1)
scrollView.addSubview(bu2)
scrollView.addSubview(image)
Last, add this two lines.
 scrollView.contentSize = la.bounds.size

 view.addSubview(scrollView)

No comments:

Post a Comment