Question about the Storyboard and 'misplaced errors'.

I am having an extremely tough time trying to understand how constraints and interface manipulation works.

Let's take the following scenerio.


I add in a button.

I erase the button text.

I select a custom image for the button.


I resize/scale the button in the Storyboard editor and add constraints so that it sticks to the bottom left of the screen. (universal device settings)


And I get misplaced errors telling me that the image is expected to be a certain x, y, height, width.

I try doing "update frame" to use my scales instead of the original image size but it doesn't do anything at all... the errors remain.


When I run the app, the image gets stretched back to its original size.



What am I missing? Why be able to scale it if it will just keep going back to its original size?



Thanks in advance for helping and answering!

If you need images of what the constraints/errors look like let me know.

Answered by bob133 in 41925022

Creating constraints for size is just as simple as spacing constraints—just control-drag across the object, starting and ending on it. You can also add an Aspect Ratio constraint to achieve what you're looking for.


Judging by your questions, though, maybe you should read the documentation about autolayout:

Xcode help:

https://developer.apple.com/library/mac/recipes/xcode_help-IB_auto_layout/_index.html#//apple_ref/doc/uid/TP40014226

Auto Layout Guide:

https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010853

It sounds to me that maybe you're not adding enough constraints to clearly define the button frame you're looking for. You need to have constraints for position and size. Any insufficiency will result in an ambiguous and weird situation.


Now if you're trying to make the button larger than the minimum size you'll want to change the Content Hugging Priority to make it lower. You'll find that at the bottom of the Metrics inspector. Try 250 or lower to keep the button from trying to shrink itself.


If any of this doesn't answer your question, just let me know. I and others will be happy to help in more detail.

Thanks for your reply!


How do you add constraints on its size?

I want it to scale proportional to its aspect ratio according to how big the device screen resolution is.


I control dragged the edges to the margins I want it pinned to and it stays where I want it to on all devices.
It's just primarily the sizing issue that has me stumped.


I tried messing with the Content Hugging Priority but nothing was being affected.

Accepted Answer

Creating constraints for size is just as simple as spacing constraints—just control-drag across the object, starting and ending on it. You can also add an Aspect Ratio constraint to achieve what you're looking for.


Judging by your questions, though, maybe you should read the documentation about autolayout:

Xcode help:

https://developer.apple.com/library/mac/recipes/xcode_help-IB_auto_layout/_index.html#//apple_ref/doc/uid/TP40014226

Auto Layout Guide:

https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010853

Question about the Storyboard and 'misplaced errors'.
 
 
Q