Search code examples
iosswiftuiscrollviewxcode6

UIScrollView not scrolling in Swift


My UIScrollView won't scroll down. I don't know why. I already followed Apple documentation regarding to this issue.

@IBOutlet weak var scroller: UIScrollView!

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

}

override func viewDidLayoutSubviews() {
    scroller.scrollEnabled = true
    // Do any additional setup after loading the view
    scroller.contentSize = CGSizeMake(400, 2300)
}

Solution

  • You need to set the frame of your UIScrollView so that it is less than the contentSize. Otherwise, it won't scroll.

    Also, I would recommend that you add the following to your viewDidLoad method:

    scroller.contentSize = CGSize(width: 400, height: 2300)