I am attempting to change the size of a UIView
that I have placed in the Storyboard. For some reason the size does not change
but remains the same as drawn on the Storyboard. I have not hooked up Autolayout so this cannot be the reason it remains the same. My code:
@IBOutlet weak var courseView: CourseView! // CourseView is a UIView
override func viewWillAppear(animated: Bool) {
courseView.frame = CGRectMake(0, 0, 200, 200) // This is just to test!
}
I have also done the same in viewDidLoad()
but without success. Any ideas?
Acording to this answer
The methods viewWillAppear:
and viewDidLoad:
have no layout information. Any layout changes made here will be lost when viewDidLayoutSubviews:
is called later on.
If you are using auto layout you cant change the constraints at any point, but the actual change will happen @ viewDidLayoutSubviews:
If you are not using auto layout you need to update the layout @ viewDidLayoutSubviews:
or after the view is being presented (@ viewDidAppear:
or by user input)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.