I am trying to use the constraints on xcode 6 with side-by-side objects but when I use the "add missing constraints" option, all of the elements resize properly except the side-by-side buttons where they stay the same size but one gets pushed out of the view.
Image of View
And I think I need to use the "Equal heights" constraint but it is greyed out :(
Greyed out constraint Image
Can anyone help?
You need to right-click drag from one of the objects to the other one to enable that option (It needs to know what heights should be equal)
You can also:
In the Xcode document outline use Shift or Command and click on the items you want to add the equal size constraint to.
Then click the Pin button.
You can now click the checkbox to add 'equal width' or 'equal height' constraints.
Related
I added a Storyboard launch file to upgrade a project from iOS 4 to iOS 9. The app runs in the Simulator but nothing I do will centre views for iPhone5 and iPhone 6 or scale them to fill the frame. Instead they look like bonsai versions of an iPhone 4 pinned in the top left of the screen.
When I try to add constraints to centre the views by following the procedure described here, the menu will not give me options to choose the view I need to constrain.
Instead I get this.
The bottom two - Horizontally in Container and Vertically in Container - are the only options I can check. But pulling down on the arrow to the right of the text box only gives some of the options needed to Add Constraints
What do I need to do to enable the view option ?
EDIT 1.
And furthermore, when I try to constrain width and height I get this
All six options are in grey and none of the text boxes change
EDIT 2.
And using the Size Inspector to look at the view I am trying to centre and fill, the view has no constraints as shown below.
It is really starting to look like there is no simple way to launch an old app where views have been created programmatically and have Storyboard Launch automatically layout views to suit different iPhone screen sizes.
The "Horizontally in Container" and "Vertically in Container" checkboxes affect individual views. The are "binary operations". If you select more than one view, these checkboxes cause all the views to be centered in their container.
In contrast, the other checkboxes in this popup align groups of views.
If, for example, you select 4 views and click "leading edges" then it creates a set of constraints that line up the leading edges of all the selected views. (Under the covers it creates enough pairs of constraints to line up all the views by their leading edges.)
If you only have 1 view selected then only the bottom 2 checkboxes ("Horizontally in Container" and "Vertically in Container") are meaningful and the others are dimmed. As soon as you select more than one view the others should be enabled.
I had the same problem because on Show the Size inspector > Layout, "Autoresizing Mask" was selected, by changing the value for "inferred (Constrains)" it will resolve this problem
illustration
Select the view you would like to constrain. Then tap the button to the right of the one you have selected and use that menu to define your autolayout constraints. If you want it to work for all devices make sure your storyboard is on the wAny hAny size class setting.
I am trying to create four buttons within UIViewBar positioned one by one with auto layout and also everybutiton having Imageview on right side arrow. Now I dont know how to achieve for all the iOS devices. It should change size and spaces based one device width. See below Image
Select all your buttons and click on 'pin' in the storyboard (it in the right bottom corner) like in the below image
add 'Leading', 'Tralling', 'Height', 'Equal width' constraints
and select 'Align' while selecting the all four button(left to the 'pin')
and add 'Vertically in container' constraint.
or else you can add 'Top constraint' instead of 'Vertically in container' constraint.
Hey I don't know this will help you or not. But lets give it a try.:)
This is my storyboard:
This is the iPad Simulator:
For the constraints I go to the bottom right and click on the button that has a triangle with two extruding bars (it sort of looks like a star wars fighter with a triangle as the cockpit). I scroll down to the section that says all view in view controller I click on clear constraints. Then I go back to the same button but this time I click add missing constraints.
Why is this happening? How can I fix it?
Adding missing constraints doesn't mean "add the constraint I think will look better in my project". Xcode adds some constraints to keep everything in place, but this may (or may not) be what you want.
To paint a control in place without ambiguity your need at least 4 constraint, two on each axe (two for X, two for Y). I recommend to clear all constraints, and start control by control, adding constraints.
Some tips:
you can set the constraints, then move a control, ask Xcode to refresh the constraints to the new position with the update Constraints option. update frames option do the opposite: given a set of constraints, repaints your control in the right position.
Use the Assistant editor to split your Xcode view, so you can select Preview and have while designing your Storyboard and see how it looks. You can add different devices to see how it fits (little + button at the bottom)
In the Xcode 6 betas, when I delete a constraint, it doesn't remove it completely, but grays it out. I thought that was to imply that the constraint was used in a different size class, but that doesn't seem to be the case. Also, how do you permanently delete these constraints?
There are a few ways to delete the constraints from the Storyboard
Try not to delete from the Storyboard object because sometimes different constraints can stack together and you might delete the wrong one. So, it is better to delete from the Document Outline. Just highlight the constraint that you want to delete on the Document Outline and just press delete button on your keyboard. See screen shot below:
If you want to clear all the constraints from a selected view, Select the View (eg: A button), Tap on the Third Button (Resolve Auto Layout Issues Button), Tap Clear Constraints.
If you want to clear all the constraints for all the views inside the view controller, Highlight the right view controller Object inside the storyboard, Tap on the Third Button (Resolve Auto Layout Issues Button), Tap Clear Constraints under the "All Views in the View Controller".
Double click the grayed out constraint (switches focus to the constraint) then press delete. This will delete the constraint.
I believe the answer to the following question is that you can have same constraint selectively "installed" (or to my understanding, enabled) for different size classes. After you select a constraint from Document Outline, you can click on the + sign to Add Size Class Customization from the bottom of Attribute Inspector. So when you delete a constraint from the Size Inspector, you're basically deleting a constraint for a particular size class only. In order to delete a constraint for all size classes, you have to delete from Document Outline.
Why? Why can't you completely delete a constraint from the size
inspector?!
You can not delete grayed out constraints from the right hand Size Inspector (which is where I normally delete constraints because it's much easier to ascertain which view the constraints are for, it get's really confusing in the Document Outline), but you can delete the same grayed out constraints from the Document Outline on the left by selecting them and hitting the delete button.
Example of grayed out constraint (see height):
Note: To make the Document Outline's constraints easier to digest, I first delete them from the Size Inspector, which grays them out, then delete the newly grayed out constraint from the Size Inspector. Just FYI.
That's because of size classes, you can disable size classes from File Inspector and every greyed constraints runs out, you can re-enable them again if you need them.
Hope it helps
In interface builder I placed a button here:
However when I run the iOS Simulator (device: iPhone 5s) it appears here:
I am using Xcode 6 Beta 4
I would recommend you to use size classes due to new iOS screen sizes, but you still can disable size classes on the interface builder in the file inspector as you can see on the image:
If you would like to use Autolayout you can do it adding the next constraints (see the first image) in the corresponding View. In the second step you should use the width and height corresponding to your View. In the second image you can see a recapitulation of all the constraints and a simulator screenshot.
Images:
This is not actually anything to do with size classes. This is due to the fact that it is assuming you have placed it approx. 200 points from the left edge.
What you haven't done is added AutoLayout constraints to say that you actually mean the centre.
CTRL-drag from the button to the view and add...
Center X values
Top space to superview
(Or something like those)
Tha will make it work.
Old question, but still question... You have 2 chooses:
Disable auto-layout
Use auto-layout to center this button on any size of display (go to "Add New Alignment Constrains", check "Horizontally in Container" and then click "Add Constrains")
(Xcode 10.1)
In the small Triangle Menu: Select "Clear Constraints"
Then Select "Add Missing Constraints"
You can also manually adjust constraints by selecting one in the scene.
Then grab the constraint handle.