Reputation: 187
I am having a couple of issues with the layout of my app, I have a few views that I layed out no problem using the 'add missing constraints' option in Xcode. Now I have a view with 2 buttons and I can't seem to get it right..I will point out now I am self teaching myself so apologies if this is straight forward. I can't post images yet so I'll try and explain below what I want
-----------------------------------------------
|
|
| ---------------- ----------------
| button 1 button 2
| ---------------- ----------------
|
|
|
|
|
|
|
|
|
Apologies for crude drawing but this is how the buttons look in storyboard, if I run the simulator only button1 is visible, if I use the 'add missing constraints' option the buttons end up on top of each other..any help would be appreciated. Thank you Great thanks for the up vote here are images!
This is what I want
and this is what I get without contraints (and suggestion below)
and this is what happens when I add missing constraints with Xcode
UPDATE: Okay guys, thank you for all the comments and answers, Between @Travis M. and @Fogmeister I have figured out the whole constraints section of Xcode.I really appreciate. Technically neither of ye answered the question here so I don't particularly know what to do as regards marking an answer. @Fogmeister switched the lightbulb on above head though so credit to him...Thanks
Upvotes: 1
Views: 245
Reputation: 2142
Check your view hierarchy and make sure that the UIButton's are in the same super-view. I would also manually set the constraints in Interface Builder: - click on the 'width' and 'height' check-boxes - set the 'left' and 'top' spacing values ("Use Standard Value")
Upvotes: 0
Reputation: 11257
Where do you want the buttons? If you want to basically appear how you laid them out on any canvas, then I would highlight both buttons and in Storyboard tap on third button in lower right (looks like triangle inside of goalpost) and select "Clear Constraints From Selected Views".
Then select tap on the second button and select these items to set them up as you laid them out.
I think the issue is that "Add Missing Constraints" tries to make some educated guesses on what your alignments might be and it's sometimes wrong.
Also, make sure you have no alignment/constraint warnings. if you do, you're still missing something (maybe a parent view of the buttons, etc).
Upvotes: 2