EDIT: added a snapshot.
I have a UIView class, as follows..
class CreateNewUserView: UIView{
private let subVu: UIView! = UIView()
func createNewUserVuLayout() -> UIView{
subVu.frame.size = CGSize(width:320, height:320)
// adding programmatically-created buttons, labels, textfields, etc..
return subVu
}
// will call the function below in a different ViewController class
func centerTheVu(superVuX:CGFloat){
subVu.center.x = superVuX
}
in a different .swift file, I have the following UIViewController class..
import UIKit
class CreateNewUserVC: UIViewController{
private let instanceOfCreateNewUserView = CreateNewUserView()
override func loadView(){
super.loadView()
view.addSubview(instanceOfCreateNewUserView.createNewUserVuLayout())
// Calling the function from the UIView class now. Working perfectly!
// the view is centered horizontally as expected.
instanceOfCreateNewUserView.centerTheVu(superVuX: view.center.x)
// However, if I delete the above line, the line below does not accomplish
// the same task when I try to do the same vertically!
instanceOfCreateNewUserView.center.y = view.center.y
}
}
Is there a reason why it's not working in the second case?
instanceOfCreateNewUserView.center.y = view.center.y
also, the following doesn't work..
instanceOfCreateNewUserView.center.y = self.view.center.y
The app builds and runs, however, the view is aligned horizontally, but not vertically.
I'm new to swift and trying to figure out how to build/ align control elements programmatically.