Problems with Constraints

Hi,

I have problems with a view, i apply the constraints but the view have a white space when i try to run on the iphone 6 plus simulator.

This is the correct view in iphone 5

Why when i run the same view in iphone 6 plus is display this?


There is a solution for see into the iphone 6 the element of view into the correct style?

Thank you very mutch

Daniele Calise

Simple: Don't use contraints. Whether you create them in interface builder or you code them manually, constraints result in a mess. Life is too short for blind conformity to a bad idea.


Regarding manual coding using constraints, I've compared manual NSLayoutConstraint code side-by-side with my own code-based layout, and it is always the case that Apple's constraints require more code and are less understandable than properly coded layouts.


Lots of newbies have a strong opinion that one has to do things the official Apple way. That is evangelical group think.

I urge people to think for themselves, and not give in to the cultlike mentality.


- (void) layoutEverything
{
     const float margin = 5;  
     const float spacing = 5;
     float x=margin, y=margin;
     _buttonFoo.frame = CGRectMake (x,y, BTN_WIDTH, BTN_HEIGHT);
     x += BTN_WIDTH + spacing;
     // Etc...
}

Auto layout lets you do things that are very difficult using manual layout, such as "pinning" a view that's inside a scroll view so that it "stays put" relative to something outside a scroll view as the rest of the content scrolls, or making a whole set of labels / views the same width with dynamic content or localization.


Yes for some cases manual layout is the best. For example I recently found myself positioning some labels on the axes of a graph. Simpler to just set the center property in that case rather than trying to set up constraints. But for the vast majority of cases (particularly where you don't have to write code...) I find auto layout to be the easiest way to handle the 4 different iPhone screen sizes automatically.


I think we can all agree the constraintWithItem:... and even the constraintsWithVisualFormat API are, shall we say, messy in code. I prefer to do as much in IB as possible.


Anyway, that argument aside, the OP's problem is most likely in the "i apply the constraints" step. *What* constraints were applied? If you just blindly choose "reset to suggested constraints", well, that will almost always end in failure. Xcode is not a mind reader; it can't know whether you want a view to stick to one edge and remain the same size, or resize to fill the space. You must add constraints yourself so things are positioned and sized the way you want them. (BTW, pasting images into posts does not work. Nobody can see them.)

Problems with Constraints
 
 
Q