I need to set the contentSize
of an UIScrollView
outside of the loadView
function.
However when trying to do so, I have the error 'UIView' does not have a member named 'contentSize'
.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
var bigRect = view.bounds
bigRect.size.width *= CGFloat(someInt)
view.contentSize = bigRect // 'UIView' does not have a member named 'contentSize'
}
override func loadView() {
view = UIScrollView(frame: UIScreen.mainScreen().bounds)
}
}
Thanks !
Notes:
view
is indeed an instance of UIScrollView
but sending it contentSize
gives me the same error.view
by self.view
doesn't solve the issue ; there is no local variable interfering here.view
is an UIViewController
attribute of type UIView
. So you should configure the scroll view within a local variable first and then set it to the view variable :
override func loadView() {
var scrollView = UIScrollView(frame: UIScreen.mainScreen().bounds)
scrollView.contentSize = <Whatever>
view = scrollView
}
If you plan to change the scroll view later you should consider either:
view
attribute as UIScrollView
(pretty bad practice) E.g:
class ViewController: UIViewController {
var scrollView:UIScrollView!
override func viewDidLoad() {
var bigRect = view.bounds
bigRect.size.width *= CGFloat(someInt)
scrollView.contentSize = bigRect.size
}
override func loadView() {
scrollView = UIScrollView(frame: UIScreen.mainScreen().bounds)
view = scrollView
}
}