Code Block
Hello from NY o/
On the many projects, I was working out with Storyboards.
From now on, I'm beginning with View Code and I'm trying to change the size of the UIView as something like that: e.g
Code Block class ViewController: UIViewController { // MARK: - Subviews private lazy var containerView: UIView = { let view = UIView() view.backgroundColor = UIColor.green view.frame.size.height = 200.0 view.frame.size.width = 300.0 view.sizeToFit() view.translatesAutoresizingMaskIntoConstraints = false return view }() // MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.white view.addSubview(containerView) containerView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true containerView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true } }
And the size of the View is not sizing. I need use CGRect to change the size of the UIView? But how to center with auto layout when CGRect(x: 0, y: 0, height: 200, width: 350)?
The x & y stay to hard to keep center x & center y at any screen size?
Thanks a lot for you help.
Cheers.
Code Block