Bottom Margin in iPhone X using storyboard - ios

Ok I have this case,
There is this screen I designed for iphone 8
As you can see here there is 8px green view that I pinned to the bottom of the superview by making a constrain of 0px between this view and top of bottom layout guide. and it works fine on all phone EXCEPT for the new iPhone X where this happens:
and thats not my intended behaviour. I want to to be as the other iPhones, pinned to the bottom with 0 margin.
Is there is a solution for that using the storyboard? Please post solutions using storyboard only. I know that I can do it programmatically. this should be easy on storyboard I guess.
Thank you

1- Select your view in storyboard

2- Double click on bottom space constraint and select Superview for first item
3- Set constant value to 0

You can achieve this
By Setting AutoResizing like this in storyboard
With AutoLayouts

In storyboard select "View as: iPhone X" and pin the desired view to superview, not Bottom Layout Guide or Safe Area (in my example it's a full screen image view, your view would be pinned only to bottom):
Alternatively, if you are not in iPhone X view, you can pin bottom edge to superview by dragging with ctrl key and then when selecting from the list, press option key - more details in this answer: Autolayout: Add constraint to superview and not Top Layout Guide?

Related

Align to the edge of the screen on iPhone X

How can I align a view to the top edge of the screen beyond the safe area?
Go ahead a select Top Space to Safe Area to create the top alignment constraint. Then select that constraint in the Storyboard or the Document Outline and examine it in the Attributes Inspector.
Click on the First Item which is Safe Area.Top and in the pop-up select Superview to align it to the Superview instead of to the Safe Area. Set the Constant to 0 and you're done. Your view is now aligned to the top of the screen.
Here it is running in the iPhone X simulator with the red view aligned to the top of the screen:
In the bottom right of that view there are three or four buttons that help you set up constraints. One of them shows you a popup where it lets you create constraints for leading, trailing, top and bottom. (I think it's the second from the right. Xcode is updating right now and I can't open it to verify)
By default it will create the constraints to the safe area but there's a down arrow you can click and there you can choose the view as the constraint target. If you also set the constant to 0 then your view will be aligned at the top to the view.

Getting a white space at bottom of iPhone X screen (Xcode 9)

I'm using Xcode 9 for my project and I'm getting a white space at the bottom, here is the screenshot:
Also I'm using storyboard to design with 4 inches (iphone 5s/SE) as layout.
How to avoid the white space?
Your bottom constraints should be from view not from the bottom layout guide or safe area(xcode 9 specific) and your distance should be zero.
Default it was pinned with layout guides, so give it with view !
Refer below screenshot for better understanding,
to open this dialogue, click drop down icon of field contains 0!
You can do same for top constraint also!
Update :
Second main important thing,
you should use storyboard for your launch or splashscreen. If you are using launch image then replace it by new launch image of xcode 9 and it have option for the image of iphone x.
Then you will not found white space any more!
Refer below screenshot.
This white space is your main view. If you want your image view to fill the whole area, pin it with 0 space to the superview, not to Bottom Layout Guide or Safe Area. To achieve this, select to view scene in storyboard as iPhone X and pin the image view as below:
It is also possible to pin the bottom of image view to superview when not in iPhone X mode: when you pin by dragging with Ctrl, when the list of constaints appears press Option key (alt) and you will see "Bottom Space to Container Margin".
Neither of the two answers above worked for me. Only setting
scrollView.contentInsetAdjustmentBehavior = .never
I have a stackView inside my scrollView and the elements in the stackView have fixed sizes, so I have no need to inset adjustment and this works.
Credit goes to How to get rid of safeAreaInsets on UIScrollview (iOS 11, iPhoneX)
For me this worked:
1) Select image for which you are setting up constraints
2) Go to Attribute inspector in the right panel
3) Select Scale to Fill as Content Mode

UIToolbar not positioned at the bottom on device but appears ok in storyboard

I'm testing the new universal storyboard in XCode 6. I basically created a view with a toolbar positioned at the bottom. When I run that basic example in the iPad the toolbar is not at the bottom
And here is in the storyboard
How can I place the UIToolbar at the bottom and using all the available width for all different screens?
Use Autolayout.
Set the left margin, right margin and bottom space constraints on the toolbar to make it dock at the bottom. Optionally, add a height constraint if you want the toolbar height to be something other than the standard 44.
Your constraints on your toolbar in the storyboard should look like this:
1:

Autolayout: Add constraint to superview and not Top Layout Guide?

I have a UIView in my UIViewController in storyboard which I want to add a constraint on to space that view a distance from the top edge.
Now, when I do the usual by ctrl + drag to the ViewController's main view I only get option to set it to top layout guide.
This is a problem for me because at one point in the app Im going to move the main view up around 20-50px and what happens then is that view I have will not move... because its not aligned to superview.
How can I manually do this in storyboard or do I have to add it programatically?
Im using xcode 6.
There is an arrow to the right of the constraint constant value. If you click on it, a menu pops out where you can choose what is it that you want to make your constraint relative to. If you choose 'View', than it will pin it to the top of the view.
You should be able to do it by highlighting the view you want in the storyboard and then selecting Editor > Pin > Top Space to Superview in the top menu.
This is outdated in XCode 7, see #PaulGurov's answer instead.
TL;DR: You can constrain to the margin by pressing the Alt key on the keyboard.
One can also add that if the view you are trying to pin is not a direct subview of the view that you want to pin it to, the suggested approach is not really valid. Let's say the view hierarchy looks like that and you want to pin the image view (Parallax Image View in this case) to the view controller's view (View in this case).
To do that you just Control + Drag from the Parallax Image View to the View. That presents the default choices where you can see Vertical Spacing to Top Layout Guide to pin the Parallax Image View to the top layout guide.
What you want is to pin it to the top (margin) of the view. To do that you have to switch to the other set of constraints by pressing Alt
I had a whole bunch of constraints already there and I just wanted to change them rather than break them. Turns out if you double click on the constraint to edit, then click on the item that has the ".Margin", you can just turn off the "Relative to Margin" by selecting that item.
Dan's answer works. I just wanted to state that if you set your view in storyBoard at y < 20, and configure constraints through the pin panel, it will set top to superview:
If the height of the view is set to 0 by accident, Vertical Space to Top Layout Guide will NOT appear. Vertical Space to Bottom Layout Guide will appear, however, which must have made sense to someone inside Apple circa 2004.
None of the above answers worked for me, instead I have to do a hack to set my subview's top with superview's top instead with Top layout guide.
First, set the subview center vertically with superview.
Then, change the Center Y constraints for subview as well as superview to Top constraint.
You are good to go now.

Desgin ViewController with Storyboard

I design the ViewController include 1 UIView and 1 button in it but when i deploy in the Emulatore, it 's not the same as what i see in storyboard file.
This is a consequence of the auto layout constraints you have. The default screen size in the storyboard is for iPhone 5, but the default simulator is an iPhone 4 size, so by having fixed distance to both the top and bottom of the screen, the view has to be squished to satisfy the constraints.
To fix this, you should give the view a fixed height (from the menu, Editor --> Pin --> height), and then delete bottom constraint.
You can also use distance to superview to top, also set the virw height constant. You dont need the bottom constraint

Resources