Can I change multiplier property for NSLayoutConstraint?

Here is an NSLayoutConstraint extension in Swift that makes setting a new multiplier pretty easy: In Swift 3.0+ import UIKit extension NSLayoutConstraint { /** Change multiplier constraint – parameter multiplier: CGFloat – returns: NSLayoutConstraint */ func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint { NSLayoutConstraint.deactivate([self]) let newConstraint = NSLayoutConstraint( item: firstItem, attribute: firstAttribute, relatedBy: relation, toItem: secondItem, attribute: secondAttribute, … Read more

How to adjust height of UICollectionView to be the height of the content size of the UICollectionView?

I would suggest the following: Add a height constraint to your collection view. Set its priority to 999. Set its constant to any value that makes it reasonably visible on the storyboard. Change the bottom equal constraint of the collection view to greater or equal. Connect the height constraint to an outlet. Every time you … Read more

Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint

I would recommend to debug and find which constraint is “the one you don’t want”. Suppose you have following issue: Always the problem is how to find following Constraints and Views. There are two solutions how to do this: DEBUG VIEW HIERARCHY (Do not recommend this way) Since you know where to find unexpected constraints … Read more

How to add constraints programmatically using Swift

Do you plan to have a squared UIView of width: 100 and Height: 100 centered inside the UIView of an UIViewController? If so, you may try one of the 6 following Auto Layout styles (Swift 5 / iOS 12.2): 1. Using NSLayoutConstraint initializer override func viewDidLoad() { let newView = UIView() newView.backgroundColor = UIColor.red view.addSubview(newView) … Read more