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

List of Constraints from MySQL Database

Use the information_schema.table_constraints table to get the names of the constraints defined on each table: select * from information_schema.table_constraints where constraint_schema=”YOUR_DB” Use the information_schema.key_column_usage table to get the fields in each one of those constraints: select * from information_schema.key_column_usage where constraint_schema=”YOUR_DB” If instead you are talking about foreign key constraints, use information_schema.referential_constraints: select * from … Read more

Remove all constraints affecting a UIView

This approach worked for me: @interface UIView (RemoveConstraints) – (void)removeAllConstraints; @end @implementation UIView (RemoveConstraints) – (void)removeAllConstraints { UIView *superview = self.superview; while (superview != nil) { for (NSLayoutConstraint *c in superview.constraints) { if (c.firstItem == self || c.secondItem == self) { [superview removeConstraint:c]; } } superview = superview.superview; } [self removeConstraints:self.constraints]; self.translatesAutoresizingMaskIntoConstraints = YES; } … Read more

PostgreSQL: default constraint names

The standard names for indexes in PostgreSQL are: {tablename}_{columnname(s)}_{suffix} where the suffix is one of the following: pkey for a Primary Key constraint key for a Unique constraint excl for an Exclusion constraint idx for any other kind of index fkey for a Foreign key check for a Check constraint Standard suffix for sequences is … Read more