On mobile devices, it is difficult to display all content on one screen. It’s almost always scrolling to see more

IOS provides UIScrollView for scrolling.

       let scrollview = UIScrollView(frame: CGRect(x: 0, y: 10, width: self.view.bounds.width, height: 600)) 
        let img =  UIImage(named: "aaa")
        let view = UIImageView(image: img)
        scrollview.addSubview(view)
        scrollview.contentSize = img!.size
        
        self.view.addSubview(scrollview)
Copy the code

UIScrollView mainly needs to set the width and height of its own controls to determine the size of this component. You then need to set the contentSize property to specify the scrollable range of the content.

For those of you who have experience with Android development, you’ll notice that this is a little bit different than using Android ScrollView. IOS doesn’t have a property to specify the scrolling direction, but the width of the contentSize determines the scrolling direction.


Welcome to follow my wechat search public number [Qingcheng Students] and share some technology and interesting things with you from time to time