swift set constraint programmatically

yourHeightConstraintOutlet.constant = someValue
yourView.layoutIfNeeded()

4.5
2
Adam Naylor 105 points

                                    override func viewDidLoad() {
    let newView = UIView()
    newView.backgroundColor = UIColor.red
    view.addSubview(newView)

    newView.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint(item: newView, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0).isActive = true
    NSLayoutConstraint(item: newView, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: 0).isActive = true
    NSLayoutConstraint(item: newView, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 100).isActive = true
    NSLayoutConstraint(item: newView, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 100).isActive = true
}

4.5 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
ios swift constraint automatically change constraint in ios swift editable constraint swift code give constraint to VIEW in code swift ios swift update constraints programmatically swift programmatically add constraints how update a constraint in swift add constraints right way swift programmatically constraint swift programmatically programmatically constraints swift 5 add constraint programmatically swift swift modify constraint programmatically edit constraints swift programmatically add constraints swift update top constraint programmatically swift ios constraints programmatically to a view swift swift 5 add constraints programmatically constraint adding function in ios swift Constraints Programmatically in swift 5 how to edit constraints in swift constraints swift programmatically add constraint example swift 5 set constraints programmatically swift adding constraints programmatically swift constraints in swift ui update constraints programmatically swift setting constraints programmatically swift set constraint programmatically swift ios swift iboulet constraint programmatically ios swift constraint programmatically setting constraints progamatically swift constraints swift swift func for constraint swift ways to setup constraints create constraints programmatically swift constraint programmatically swift ios how to add costraints progratically in swift swift width constraint programmatically swift add width constraint programmatically swift get constant of contstraint reset value constraints programmatically swift swift 5 centerYAnchor swift add constraints programmatically how to give constraints programmatically in swift change constant swift top constrain of view programatically swift swift update constraints programmatically set constraings programically ios swift swift set width constraint programmatically ios swift how to get constraint of a view dynamically ios swift how to get a view constraint programmatically swift programmatic constraints how to use the relation height constraint swift viewTopHeightConstraint.relation swiift how to create a width constraint in code properr way to ddo programatic constraints swift swift change NSLayoutConstraint programmatically swift add NSLayoutConstraint programmatically swift get height constrain swift set constraint programmatically how to make view programmatically constraint in swift CONSTRAINT code swift add custom constraint constraints code ios constraints programmatically ios constraints programmatically tutorial change constraint swift 5 add constaint in uiview swift 5 button not showing with auto constraint swift programmatically swift set view bottom constraint programmatically swift get NSLayoutConstraint.activate swift update view NSLayoutConstraint swift update constraint how to programmatically add constraint equal to view in swift ios how to set relation between two attributes greater tahn or samller than manually in swift how to use programatically constraint and static constraint at one time in swift after giving new constant to view it add new contant in the older constant in swift how to change the constraint of uiview in swift how to give dynamically constraint in swift how to give constraint from one item to another item programatically in swift horizontal(to ) tiny constraints swift programmatically change leading constraint value swift 4 swift set nslayoutconstraint programmatically swift how to constrain a UIView inside a view height constraint create constraint for height porgammaticaly swift swift auto layout programmatically how to add constraint s in swift add constraint with format swift 4 get height constraint swift swift 4 how to extend nslayoutconstraint programmatically change constraint programmatically swift swift 5 constraints programmatically swift set a layout constriant programmatically how to add bottom constraint to other view in swift programmatically swift programatically add constraints constraints swift programmatically for every iphone devices stackoverflow constraints swift programmatically for every iphone device how to make constraint for every different version of iphone programmatically swift stackoverflow swift change constraints programmatically equalorabove constraint swift how to add contraints swift 5 Which method is used to add any control on view? addObserver addSubview addConstraints addConstraint add constraint between two views programatically swift 5 add constraints programmatically swift 5 set height multiplier constraint programmatically swift add constraint to view programmatically swift auto layout code xcode swift constraints programmatically anchor swift set x constraints programmatically changing constraints programmatically swift update constraint programmatically swift set top constraint programmatically swift how to add height constraint programmatically swift how to give height and width constraint programmatically in swift ios swift programmatically constraints constraints for 4 views swift view with multiplier from other view swift is it required to add NSLayoutConstraint in the viewDidLoad swift programmatically create constraints swift swift set constraint programmatically toItem swift activate constraints programmatically label swift constraint add constraint to view swift swift autolayout constraints in code ios swift constraint width change at end swift modify constraint programmatically swift create height constraint property programmatically swift create height constraint programmatically constraints to table view padding top programmatically swift add constraint swift programmatically add constraints to view programmatically swift add constraints to view swift cell constraints programmatically swift height constraint swift ios swift height constraint programmatically swift constraint to other view swift constraints programmatically how to set constraints programmatically in swift how to add constraints programmatically to super view ios swift how to add constraints programmatically ios swift swift add height constraint with multiplier add constraint swift add bottom constraint programmatically swift update Constraint swift swift how to edit constraint swift set constraints programmatically ios how to create a uiview with programmatic constraints in swift change height constraint programmatically swift swift translate between two constraints swift update auto layout constraints programmatically nslayoutconstraint programmatically swift add view constraints programmatically set height constraint programmatically swift for subview swift height constraint outlet change constant with animation swift height constraint outlet change constant add constraints programmatically swift reload constraints swift add constraints programatically uiview dynamic height autolayout programmatically view add constraint add bottom constraint programmatically swift 5 change aligncenter constraint value programmatically swift add constraint swift programmatically ios how to set constraint programmatically in swift 4 swift programatically constrain to top swift change constraint programmatically swift programmatically add contraints xcode swift constraints programmatically how to put constant between view and view swift programmatically add constraints programmatically swift swift edit constraint programmatically
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source