Skip to content

Instantly share code, notes, and snippets.

@danstepanov
Last active October 3, 2021 07:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danstepanov/b4ebfba03a0cfa00fa12 to your computer and use it in GitHub Desktop.
Save danstepanov/b4ebfba03a0cfa00fa12 to your computer and use it in GitHub Desktop.
func textFieldConstraints() {
// Center Text Field Relative to Page View
NSLayoutConstraint(
item: textField,
attribute: .CenterX,
relatedBy: .Equal,
toItem: view,
attribute: .CenterX,
multiplier: 1.0,
constant: 0.0)
.active = true
// Set Text Field Width to be 80% of the Width of the Page View
NSLayoutConstraint(
item: textField,
attribute: .Width,
relatedBy: .Equal,
toItem: view,
attribute: .Width,
multiplier: 0.8,
constant: 0.0)
.active = true
// Set Text Field Y Position 10% Down From the Top of the Page View
NSLayoutConstraint(
item: textField,
attribute: .Top,
relatedBy: .Equal,
toItem: view,
attribute: .Bottom,
multiplier: 0.1,
constant: 0.0)
.active = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment