UIScrollView not scrolling in Swift

Mohammad Nurdin picture Mohammad Nurdin · Jan 26, 2015 · Viewed 76.4k times · Source

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)
}

Answer

Christian picture Christian · Jan 26, 2015

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 scroller.contentSize = CGSizeMake(400, 2300) to your viewDidLoad method.