How can I set aspect ratio constraints programmatically in iOS?
Layout Anchors is the most convenient way to set constraints programmatically. Say you want to set 5:1 aspect ratio for your button then you should use: button.heightAnchor.constraint(equalTo: button.widthAnchor, multiplier: 1.0/5.0).isActive = true Here’s the full code: class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let button = UIButton(type: .custom) button.setTitle(“Login”, for: .normal) button.backgroundColor = … Read more