Adding Spacing Constraints to Text Field - ios

I have a simple storyboard with a text field. I want to add spacing constraints to this text field so that, when I rotate the device, the text field will auto stretch across the screen instead of stopping halfway.
I have looked at multiple tutorials and they all say to "Control-drag from the text field toward the top of the scene, ending in the empty space around the text field. This should reveal a pop-up menu from which you can edit the spacing constrains of the text field."
However, when I control-drag from the text field, I get this different pop-up menu:
This other pop-menu clearly does not allow me to do anything with spacing constraints. In fact, I can't click on it at all.
Furthermore, clicking "Editor > Resolve Auto Layout Issues" does not work, as the entire sub-menu is grayed out.
How can I correctly add a spacing constraint to this text field so that when I rotate the device the text field will correctly fill up the screen? Please try to refrain from answers that involve editing code, as I don't actually know any Objective-C and would like to make this effect in the storyboard.
NB - If it is at all helpful, I am following this tutorial. Albeit it is with Xcode 5, other tutorials on Xcode 6 suggest the same pop-up menu should exist.

You probably didn't activate auto-layout in the first place. Check the option in the right panel, under the File section:

It's a new behavior of IB
For example:
Now the contents of the menu depend on the edge of where you are trying to tie constraint:
or simple use tree from left of IB

Open the document outline to see the view hierarchy and try control dragging the text field to the View, it should show the options there. Your menu appears when you control drag onto the View Controller.

Related

How do I measure the distance between UI elements in Xcode?

I'm trying to determine the distance between UI elements in my app, to check that the layout matches that specified by designers. I'm using the 'Debug UI Hierarchy' option, and I do see the representation of the phone's UI in Xcode. However, the only way I can see to determine the relative positioning of two elements is to look at the Size inspector in the right sidebar, and do a manual calculation on their provided measurements. Is there a better way to do this? Can I select one element and then select another to compare it with?
I now its been a while since you asked your question but I've faced the same problem and I could figure out how to measure NSConstraints between views in runtime.
First, you have to click the debug view hierarchy icon on the debug area as shown on this picture:
After pressing the button a snapshot of the Views hierarchy will be shown on the Xcode screen as follows:
You can see all the elements (UIViews) that are actually being displayed (or not, they can be in the background) on the screen of the device
After this, you can press on the show constraint icon to show the constrains that are being applied to every view on the screen, you'll have a screen pretty similar to the interface builder constraint layout:
If you select on a particular constraint (the one you actually care about), i.e in this screen I want to know the distance between the top and the ImageView that is being represented by the big square. So selecting on that particular constraint and clicking on the inspector Object inspector icon inside the Utilities panel you can actually see the constraint description.
This way you can see the constraints measures and the relation with the views and frame bounds.
You can press "Option key" and the UI element on StoryBoard this will show distances between this element and any other
I hope this helps

How can I style a text field in iOS (Swift)?

I am a beginner and just started learning iOS. I want to achieve this layout, using Swift:
When you drag a text field into your project, there's a number of styling options available in the Utilities bar in Xcode, that can help you style the shape, colour and other properties of your field. To achieve the look you want, you could use something like this:
Place a UITextField and a UIButton on your story board. Then select both items, and then go to Editor, Embed In, stack view. If they are one on top of the other, change the stack view orientation to vertical then they will be side by side as shown above. Next change the attributes of both in the attributes inspector to taste. You can change the attributes manually in code using textField.defaultTextAttrubutes = [ "the look you are going for"], but you should need to in order to recreate your example.
you can add a view container to your view, inside that container .. add a button and a textfield then add positioning constraints on them.
as you can see in the picture .. it illustrates the idea .. you can style it the way you want e.g. change the height of your textfield .. change its border style etc. the same with your button.
example
In order to add a border, you have to enter some specific information in the attributes inspector. Here is a snapshot of what you can use to create border radius if you want one, vary the thickness of the border, and select a color for the border. screenshot of attributes inspectorYou can vary the values to make the radius greater and the width thicker also, plus you can change the color. Pay very close attention to the spelling otherwise this won't work.

StoryBoard Different screen sizes iOS

I'm trying to make an app. I prepared the ui with sketch app.And I export the ui , it is like this:
I add some text field and button to View
But when I use Auto Layout and constraints buttons and text fields are going to another place.I need the use them like in the picture.What should I do ? Do you have any suggestion ?
Thank You
Notice the red arrow at the top right of your second screen shot. That is telling you that your constraints are faulty. Until you fix them, you will not see your interface widgets in the desired locations.
In general, as long as you see a red or yellow arrow in that spot, you need to work on your layout some more. Do not attempt to run a project when Interface Builder shows you that red or yellow arrow; your results will be disappointing, to say the least.

UITableview blocking uiview

So I had a UITableView that I tried to make smaller by adjusting its constraints. I then added three labels and textfields to my UIView. However, upon running the app the UITableView doesn't seem to have been made smaller, instead it's "overlapping" my labels and textfields. Here is a picture of what I am describing. http://imgur.com/BoC6l1R. And here is a picture of the storyboard editor. Note the dotted lines. http://imgur.com/wUyccDk. I've tried changing many things with the constraints but they all make everything more messed up. I feel like the solution should be pretty simple. Thanks!
In the second image (the storyboard) you see there's a dotted line and a yellow line with +78. That indicated that the constraint specifies that the table view should be 78 points above where it is now. That's a warning in your storyboard meaning that the UITableView will appear in a different position at runtime.
The easiest way to solve it is to open the storyboard file, then at your left there should be the Document Outline. Find your view controller, and there should be a small yellow arrow next to the view controller name. Click on it and you'll go to a screen showing you the constraint warnings. It should say "Misplaced views". Click on the small yellow arrow next to the misplaced view (your UITableView) and a popup will appear. Select "Update Constraints" and then click on "Fix misplacement". That should do it.
However, a better way to solve it is to put a constraint between your text fields and the UITableView. Delete the constraint between the table view and the top layout guide (the one appearing yellow), then add a Vertical Spacing constraint between the UITableView and the UITextField below the Sea_State label.

UIViewController with UITableView and TextField storyboard placement

This might be a simple question but using storyboard I can't seem to position my table, a message field and a button correctly. In the picture below, if it's positioned that way, only then do I get to see the text field and button at the bottom of the screen and the table view takes up the rest of the screen. If I drag the text field and button to the bottom and resize the table, the text field and button disappear and the table is cut off. Why is that? Is there a solution to this without doing it programmatically?
Easy solution is to remove all constraints then position them where you want them.
You'll find you get different effect when try to reposition items depending where you drag from for example double tap an item and nudge it with arrow keys or grab the middle to move it resizing via the corners.
But in my opinion it's easier remove all constraints from the view and then set them as you go.
Also you might want to consider using a container view for the table view and have a separate UItableViewController that way you can easily separate out that the tableview logic from the other ViewController. It will help stop things getting a little messy later on as project grows.

Resources