How to force a MapView to cover all space on ViewController? - ios

I need to show a map view to cover all spaces on the screen. I have added constrains as follow:
First I added this:
But it didn't work. Then I tried suggested constrains or tick Width and Height in above picture but still I have 2cm empty space on iPhone 6 as you can see in following image:

Uncheck constrain to margins and then add the constrains again (0,0,0,0).

Note your size class is Compact Width and Compact height
That is for 3.5,4,4.7-inch in landscape
You should choose any any
Then add constraints like this

Your size class is wCompact hCompact.
Change it to wAny hAny to get the desired output.
Opt to uncheck Constrain to margins option and add 0,0,0,0 Spacing to nearest neighbour
Do not fix its height or width els it would remain constant irrespective of iphone screen size .
U can also refer this link for more appropriate auto Layout concept.http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
Hope it helps.. Happy Coding..:)

You should do Leading, Trailing, Top, and Bottom to superview. Do this by control dragging from the MapView to the view. Just make sure that you have MapView taking up the entire view controller in the storyboard when you apply these constraints. Or, do it programmatically.

Related

Top space on device rotation

I have the following constraints on my UIView in portrait mode:
And landscape:
This is screenshot of the ViewController when I open it first time:
Top space is OK.
Then I'm rotating the device to landscape:
Do you see that white space on the top?
And when I'm rotating it back to landscape, the space still stays:
Why and how to fix it?
Try to uncheck Adjust scrollview insets Of viewcontroller attribute
Source Of Image: Here
You might have set TopConstraint of your view With margin.
Uncheck box for Add to Margin.
Considering black view about the imageview which contains Back button is a UIView (says, viewNav)
Constraints for viewNav:
if you'r changing the height of viewNav of rotation then use size classes as see below and click on landscape option. Now select your navView and click on height constraint and give c-c constraint like this
Constraints for UiImageView:
If you'r image covers the complete screen the give bottom constraint as 0.
This fixes every thing.
If you are using native navigationBar then you there will be no viewNav and now constraint for image will be
On giving top constraint, don't forget to select use standard value for top constraint then enter 64. Bottom and height is according to your need whatever you prefer.

How to set Horizontal text field in landscape mode with auto layout?

In my app i want to set text field width according screen size in landscape mode,using auto layout.it's working portrait perfectly in land scape mode not working.
Here is my Screen with auto layout,
In landscape mode showing like this,
Here is my Constraints Screen
this my View Controller
I suppose you must have some superview under this layout that has explicit width set.
How does it look like when you tweak simulated metrics like size and orientation in your storyboard?
Alse remember to double check the view hierarchy.
Check the size inspector, your contraints should be:
trailing space to superview, leading space to superview, and some top and bottom space. And don't set explicit width value
EDIT: As you can see, the view which is the superview for your textfields and actually whole layout, has the explicitly set width value. Delete this value and instead set both trailing and leading space. This would work
Constraints for scrollview - leading, trailing, top and bottom and equal width to superview.
Constraints for view inside scrollview - leading, trailing, top and bottom to scrollview and equal width to scrollview.
And the constraints given to textfields, buttons, etc. are correct. You just need to revise scrollview's and view's(inside scrollview) constraints.
Don't need to set Centre constrain. Just set top , Leading and Trialing . so, Autolayout Adjust size automatically. check below image ,
Check Output :-
EDIT :-
Here i have attached Demo with Scrollview . check it.
Constrain with scrollview
Output :-

Two uiview not fitting for all screen with same size

I am new to iOS. I am learning my self. No resource are to clear my problem.
I have two view with 270 X 338. that I have to keep in Horizontally in Viewcontroller. But, when I add some constraints it's not fitting for below 5s. I checked in simulator also in preview option.
When i use autoresizing, also it's not fitting for below 5s screen. Please help me with some idea. I need to do only in storyboard.
Thanks
I tried this tutorial Here but it din't help
This is my preview screen
Edited:
Constraints for Back View;
These steps will help you align two views.
Add top, leading, and height for first and second views.
Add trailing constraint from First view to Second view as 8.
Add Equal Width for First view and SuperView and set its multiplier to 0.49* and constant as 0.
Add Equal width for two views again by selecting two views.
Finally update constraints the view will align for all sizes.
0.49 will leave 8 points as trailing constraint.
Constraints for First View
Constraints for Second View
Edit :
For third step you can do by selecting first view and hold Control button and and move mouse to super view.
The selected view in the below image is the Superview
View 1
View 2
you can do it by adding contraints like this also
Use leading, top and relative height and width constraint that will solve your problem... set relative height and width in view with autolayout from below steps
Set equal height and width with superview.
Go to properties of constraint where you find a property multiplier in which set exact multiplier value which you want or which satisfy your constraint.
This will make height and width of view relative to superview that changes according to superview.

Setting constraints in different size classes, view does not appear in landscape

I am trying to get my head around the size classes.
I have my constraints set for compact width and any height (iPhone portrait):
This works as expected (I want the box at the top of the screen) i.e.:
Now I am trying to set the constraints for this square for the landscape orientation. I want the yellow square to stick to the left hand side of the screen in landscape. I select any wAny and hCompact in the interface builder but my yellow block isn't there to edit the constraints for:
What am I doing wrong here? I'm a little confused about what happens. Do I need to add another new yellow block or am I adjusting the constraints of the existing one? Any pointers would be much appreciated! thanks
If you want to use size classes
First select wAny hAny (This will be active on all sizes)
Add the following constraints:
Top Space to : Superview
Trailing Space to : Superview
Leading Space to : Superview
Height Equals : 220
The result on iPhone
Now add customization in any class you want. In this case we are adding customization to wAny hCompact
The Constraints on this will be:
Here two constraints (height constraint and Trailing constraint) are uninstalled for wAny hCompact as Shown in picture
Now additional constraints on this are
Bottom space to Superview
Width Equals : 220
The result on lanscape is as given:
I think your view will be disabled for wAny hCompact. Select the view from view controller scene from left pane and drag and drop to wAny hCompact view. Then set constraints.

Change view width with autolayout and size class enabled

I have done sample screen for iPhone5s with autolayout and size class enabled in swift.I have a view at top of the screen which has 320(width).How do i automatically increase width of view for iPhone6 and iPhone6Plus screen.any help will be appreciated.thanks in advance.
If you want the dimensions of your view to follow the same width as the one of the iPhone it's running on, in Interface Builder, position the view, size it so that it basically looks as you want it to look, and then add the constraints, ctrl drag from your view to it's superview and add "Leading space to container margin" and "Trailing space to container margin" constraints.
You don't set the width. You make constraints to the left and right edges of the superview so it will always be the width of the screen (assuming that the superview is the controller's self.view).

Resources