Swift Ways To Setup Constraints

[Solved] Swift Ways To Setup Constraints | Swift - Code Explorer | yomemimo.com
Question : swift ways to setup constraints

Answered by : sarwar

//https://stackoverflow.com/a/26181982/13171606
//There are multiple ways to add contraints, please open Link for almost ecery type of constraint
override func viewDidLoad() { let newView = UIView() newView.backgroundColor = UIColor.red view.addSubview(newView) newView.translatesAutoresizingMaskIntoConstraints = false//compulsory newView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true newView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true newView.widthAnchor.constraint(equalToConstant: 100).isActive = true newView.heightAnchor.constraint(equalToConstant: 100).isActive = true
}

Source : https://stackoverflow.com/a/26181982/13171606 | Last Update : Sat, 20 Feb 21

Question : swift constraints

Answered by : happy-hyena-j4t6squdpbx2

 - firstView.coverWholeSuperview() - firstView.constraints(size: CGSize(width: 44, height: 44), centerX: view.centerXAnchor, centerY: view.centerXAnchor) - firstView.constraints(top: view.topAnchor, leading: secondView.leadingAnchor, bottom: view.bottomAnchor, trailing: secondView.trailingAnchor, padding: UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12))

Source : https://stackoverflow.com/questions/26180822/how-to-add-constraints-programmatically-using-swift | Last Update : Tue, 15 Jun 21

Question : Type Constraints Swift

Answered by : samer-saeid

//create a generic function with type constraint
func addition<T: Numeric>(num1: T, num2: T) { print("Sum:", num1 + num2)
}
// pass Int value
addition(num1: 5, num2: 10)
// pass Double value
addition(num1: 5.5, num2: 10.8)

Source : | Last Update : Thu, 23 Jun 22

Answers related to swift ways to setup constraints

Code Explorer Popular Question For Swift