Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Programmatically adding constraints1

How would I programmatically add constraints. How would I make a button fit for a 3.5inch iPhone and a 4inch iPhone

2 Answers

Stone Preston
Stone Preston
42,016 Points

check out the Auto Layout in Code Guide. Looking at the guide, creating auto layout constraints in code is pretty confusing. I have not worked with it much, but that guide seems like a pretty good read

As you know, I'm trying to do the crystal ball extra credit. I got it to work in 4.0 inch, but not 3.5 inch. I have tried the page you suggested. It's a little over my head. Could you help explain some of that.

Stone Preston
Stone Preston
42,016 Points

probably not. I have never really used code constraints, I use interface builder to add constraints.

i added the button through code, is there a way to add constraints without code, to the button that i used code on. If that makes sense..

Stone Preston
Stone Preston
42,016 Points

i dont think so. if you want to add constraints using interface builder you will have to add the button using interface builder.

Thanks