0

In my storyboard I am attaching a few elements from the object library. the size of the view and the size of each of the elements is set to any. I can see the elements inside the editor but when I run them on the simulator they do not appear. I know it is launching the right scene since when i set the background colour it showed the right colour. I am new to iOS so I could really use some help with this. Any suggestions why these elements might not be showing ?

I have seen this answer and it didn't work for me because I already have all elements set to Any

Community
  • 1
  • 1
unknown_111
  • 111
  • 1
  • 3
  • 12

2 Answers2

0

You most certainly forgot to add constraints, or added wrong constraints.

To add constraints, Ctrl+click or simply right clic on the view, and while clicking, drag & drop to the superview, then select the appropriate constraints.

You can hold shift while choosing constraints to select multiple constraints, and then hit "Add Constraints".

Appropriate constraints are usually Top, Right, Left and Bottom for very simple views.

That means you set "I want the left of that view to be at 10 units of that view". Or " I want 10 units between that view and that other view".

Its a matter of setting distance between two objects. That's a rougly summarized explanation.

I suggest you play around with it, and follow guides about constraints, because they're not easy to learn at first. And also start with "simple" views :P

You can also drag & drop constraints between views themselves, not specifically superview (to create spacing constraints, or if you want two views to have "Equal Widths" for example).

All views, at all times, must have enough constraints for X, Y, W & H. If one is missing, you'll have a red warning.

Yellow warning means, most of the time, that what you're seeing is not exactly what will be rendered. You can simply "Resolve all" and the IDE will realign everything, and you can always ctrl Z if that's not what you wanted.

Gil Sand
  • 5,802
  • 5
  • 36
  • 78
  • i still can't add constraints even after i right clicked/control+clicked... but u were right since i couldn't see the view i added to the top left view as u said – unknown_111 Jul 27 '16 at 09:01
0

See screenshot attached here. I have show, how to set constraint.

EDIT

see this link : https://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

enter image description here

Bhadresh Mulsaniya
  • 2,610
  • 1
  • 12
  • 25
  • okay but what are the constraints i need to add for my elements to show ? i set the margins and put that the constraints are for all not just this size class but it still didn't work – unknown_111 Jul 27 '16 at 09:07
  • Please refer the link which I have added in my answer. You will got the answer for what is constraint. – Bhadresh Mulsaniya Jul 27 '16 at 09:30