How to make storyboards for each device - ios

Actually, I made the view showed below. But every time I run the app on different devices they're moving their places. I added constraints by using Add Missing Constraints. You can see the problem I have. Can I solve it by drawing all storyboards for each device and how?
Screenshots

Here's how to get the view the way you want it using Storyboard. I'm assuming you know how to add constraints in Storyboard.
For the yellow circle, set height and width constraints Next add a center horizontally constraint. Finally pin it to the top.
For the green and blue circles set height and width constraints. Now set the height and width of the green circle equal to those of the blue circle. Pin the green circle's edge to left edge and the blue one to the left. Finally pin both to bottom.
Alternatively for the latter circles, you could choose to add both to a third view with the same constraints in said view and center the extra view horizontally while making sure to set its height and width constraints.

Related

Stick three containers and a problem with iPhone X

I am trying to create three containers (UI Views) as in the following example:
As you can see, in my case the TopContainer (the orange one) and the BottomContainer (the red one) have different dimensions. Also, I have a MiddleContainer (the white one) which is NOT located in the middle of the screen or in the center. In fact, the BottomContainer is a bit larger than the TopContainer.
Question: how can I keep them constrained no matter which phone my user has?
I tried to constraint the three components to the margins and between each others but it's not enough because, in that case, XCode argues that for each component the height and the width are ambiguous. Therefore I tried to maintain also the Aspect Ratio for all the three components and it seems to work, but with iPhone X (like iPhone XS) I get a ugly bottom line, so the bottomContainer doesn't fill the whole screen.
I know that there should be a "Bottom Space to" to set up for my BottomContainer in order to solve this issue but apparently I have it not, as you can see on the right side of the following screenshot:
Do you have an idea of what I am doing wrong? Do you have an alternative way to proceed?
I would solve it with a UIStackView with two UIView (orange and red). The UIStackView is set to distribute Fill Proportionally.
The orange view is the size of your orange view plus the size of the white view.
Then I'd add the white view as a child to the orange view and constrain it to the bottom of that view and with a fixed height.
To get rid of the bottom gap, set the bottom constraint to Superview instead of Safe Area.
See the screenshot for details:
As per your comment, I think this is what you can do!
Align the "middleComponent" to the center vertically, to its superview.
Set the height to it, as you want to have a fixes height there.
Then pin the "topComponent"'s bottom to the top of "middleComponent".
Pin the top of your "topComponent" to the top of the superview.
Pin the top of your "bottomComponent" to the bottom of the "middleComponent"
Pin the bottom of your "bottomComponent" to the bottom of your superview.
All these views will have have their left and right pinned to the superview's left and right.
Hope this helps

Trouble with layout on various screen sizes

My screen layout has elements placed correctly
but when I switch to another screen, eg. iphone 7 plus
or se
things change. I've set constrains, height and witdh when I suppose I should, but apparently it does not want to cooperate with me. Please tell me what constrains and heights, widths should I set.
Add below constraint
For the red and green View You need to give Equal Width Constraint.
For Blue View at the center you need to give Center Horizontally Constraint.
For the bar at the bottom You need to give Bottom distance from the Red/Green Top Constraint.

Aligning two button images at a fixed distance in ios app-Swift

I am working on an ios app where I want to have two buttons at a fixed distance from each other. Something like below:
I tried dragging one constraint between the two images. But when I run it in simulator it shows overlap as below.
Can someone guide how to put both the pictures at a fixed distance. Also, I am seeing when I turn the simulator as right in hardware option some of my buttons are not getting auto aligned to horizontal screen and doesn't get displayed. How to fix this too?
Thanks
First of all clear all constraints. and follow below steps :
select both button with command button press
Give Width & Height constraints for both. (Pin at bottom-right side)
give Horizontal Centre in container constraints for both. (Align at bottom-right side)
Now, update all constraints (Resolve Auto-Layout Issue bottom-right side)
Hope, it's work..
Design your view according to this image
Drag a new view and then put your two button in it
Constraint for new view
Top
Horizontal center
Fix height and width
Constraint for left button
Top and leading
Fix height and width
Constraint for right button
Top and traling
Fix height and width
It will work defiantly.

Resize views relative to each other Xcode 6

I am building a new app using Xcode 6 and auto layout. I have only just started using auto layout and this maybe a really simple issue to fix but i have been going around in circles trying to find the right way.
I have a view played out as follows (don't have the rep to post images so have used a link instead)
http://files.parsetfss.com/48d8d860-e1c2-4671-ac59-03f46eee316b/tfss-23f6bdb8-3e5b-4ce0-b7ed-b1daf0006f33-Screen%20Shot%202015-05-22%20at%202.56.03%20pm.png
I have set constraints on the red box to keep its left,right and bottom the same distance from the superview and another to keep its height the same at all times. I then set constraints on the black and green box's keeping there top and out side edges the same distance from the superview and there bottom edges the same distance from the red box.
The aim is that the red box stays the same height and changes width with the device size and orientation, With the green and black changing height and width to fill half of the rest of the screen each and meet in the middle.
Now i have set constraints to keep the black and green the same distance from each other, and it worked as i wanted however i get warnings that the black and green boxes have ambiguous positions and widths.
The only way i have come up with to get rid of the warnings is to place a label (alpha set to 0 so it can't be seen) that is constrained to the centre of the screen then set the black and green box's contains based on the label. This works and is warning free but i am sure that this is not the best way around the issue.
So the question is how do i do this with out errors and with out placing an unnecessary hidden label.
As the view at the bottom has a fixed height...you just need to pin all edges of the all views and just need to give equal width constraints to the black and green views...just like below image...
And the output in different screens...
You need to give the black and green boxes an "equal widths" constraint. Select both boxes, and choose "Equal Widths" from the pin icon at the bottom of the canvas.
As per your requirements
1 view Black:
2 view Green:
3 view Red:
Follow these links Autolayout or Autolayout programatically
This might helps you :)

Align button with respect to background image in XCode

I have a background image and I need to put buttons in it. I have tried auto layout as well by fixing it's height and width (The button text was not part of the background, has been added manually), but it is not working for all screen sizes. I want two buttons equidistant from line that can be seen(like in iPhone 4 inch screenshot, line is part of the background). How can I go about doing that? Are there any other tools which might be helpful? I am using swift
Best way to do this is to add a hidden view which has a background color of clear. Add a constraint for this which centers it horizontally and a constraint which positions its top where you want it.
Make the width of this transparent view the space you wish between buttons or leave it as 1 wide if you wish and use offsets in the constraints described below instead. Make the height 1 so it takes up no space.
For the buttons align the top of the buttons with the bottom of the transparent view. This places the buttons vertically.
Finally pin the trailing edge of button 1 to the leading edge of the transparent view and pin the leading edge of button 2 to the trailing edge of the transparent view. Set the offset for the pins to be the distance you want the buttons from center if you gave your transparent view no width.
On all screen sizes, the buttons will now be relative to the center.
If you want to have them equally space out, you can add transparent views to the left and right of the buttons and pin them together so they act like spacers. So superview->spacer->button->spacer->button->spacer->superview.
Using the spacer approach, select the 3 transparent views and add a constraint for equal width. You buttons will now be spread apart equally.

Resources