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.
Related
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
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.
Like the title says, I cannot get the size of one of my buttons to match that in the storyboard. When I run my program, the button shows up much bigger, taking up a large portion of the screen, which the others don't do. I will include screenshots to show what I mean. I am having trouble finding out how to fix this. I've already tried Clean.
A screenshot of the storyboard, then quiz when it is run
You have to use constraints to make you button or whatever controls looks like what you want on different screens and devices. You should use your storyboard file to put your constraints.
So your button should in the simplest form should be looking in the storyboard file like:
So be sure that all your constraints are blue (blue lines on the screen). They can be orange as well but it is the signal that something can go wrong when you run your project with position or size of your button.
I am designing a simple user interface for an app using Xcode and Auto Layout. I have a view controller with three basic outlets: a static image view, a label and a button. You can see it in the picture shown below.
As you can see, I'd like to have the image view horizontally and vertically centered in the view controller, the label just below it and the button somewhere in between the label and the Bottom Layout Guide.
The problem is that I am experiencing some appearance problem with the iPhone 6 I am using for testing. The interface items are not nicely centered as they are supposed to be, as you can see from this screenshot.
I am not asking for the solution to this problem, though. I would rather know whether there are best practices to design a good user interface. For example, is there some way to temporarily hide the label and the button from the view controller to focus only on the debugging of the image view without having to remove and redesign them again?
Select the label you want to hide,then uncheck the checkbox installed
You can simply set its alpha to zero .
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.