An image view on an Image View xcode - ios

I'm developing an app using Xcode 8.1 and and swift 3.0.
Using storyboard I've expanded an image view to take up the whole view and set a picture to it to be used as a background image (using self.view.background doesn't give the image the same layout).
This works. I have defined the constraints for it plus added 2 textboxes and a button that also have constraints.
Now I try to add a new image on top of the background image, but then I cannot define the constraints for the front-most image view. I get something like this with two errors telling me to define the constraints but when I do nothing happens.

The way it looks you as per the screenshot, you should just give the padding (spacing to nearest neighbour) for left , right and top in your storyboard.
If there are any warnings just set the current constraints to supersede other views. This can be achieved by selecting the warning and then update constraints and check the box apply to all views in container. It should work.

You need to pin the imageView, what constraints have you set so far?

Just set the constraints for the front image view (as on the your screenshot as well). I don't see any problems.

have you set below constrains
1. Top Layout
2. Bottom layout
3. Leading
4. trailiing
5. height
or
horizontal in center
vertical in center

Related

Resize Stack View

I have a UILabel and a Switch on storyboard, I use Stack View to group them, however,after embedded into a horizontal Stack View, I am not able to resize the stack view but only can move it around. Why?
(I am using XCode 8 + Swift 3)
===== UPDATE ======
Thanks guys suggesting for adding constraints, but .... I added constraints, but I still would like to see the constrainted layout on storyboard instead of messed up layout.
E.g. I added constraint to leading and trailing space to be 8 pixel away from parent, but I see red line which xcode gives to indicate the actual layout is not showing in the constraint way. That's the problem, I can only drag the stack view, but I want to resize it to match my constraint so that it looks same as that in real device.
You need to add constraints to set the the placement of the StackView. To set the distance between the two controls, simply set the spacing as I've done in the image below (Spacing = 50):
You can add the width constraint to change the width.
In Interface Builder, start by dragging out a vertical stack view, and add the flowers label, image view, and edit button. Then set up the constraints as shown.

AutoLayout : Relative scaling of views

I want to achieve consistent views across different screens. My layout constraints works on small screens perfectly but it scrambles on large screens.
I have made a view(Red Border indicating that view)and pin it in to the main super view. Then I have made sub views and put it inside that view. I have pinned the the top bottom trailing and leading edge of the layout which contains button of the it's parent view (Red Border indicating that view). The view containing button is looking like this in small screen (iPhone 5)
while it's looking in big screens like this (iPhone 6 and above)
I want this layout to have the same relative height in all the screens like the other views. How can I achieve this?
I guess you can use UIView that contains a button inside and set bottom,lead,trailing,top constraints for the UIView. Then you can set height constraint of that UIView and set multiplier values to have relative height to its superView(=Red box). Finally, you can set constraints for your button inside the UIView whatever you want. If you know how to use StackView, I recommend you to use it because it is easy and simple solution. Here is very good tutorial about StackView.
If height is constant for subview except that button view the layout will be like what you mentioned in the first image .If you kept height as constant for that button view the problem will be solved

What must I do to add a constraint to a view in a Storyboard launch file?

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.

iOS Swift, Constraint pushing view off sotryboard

I'm working on my first swift app and I found out quickly that I need to use constraints to properly layout my page. So far I'm running into two issue.
The first one is that after adding some constraints, my view is pushed off the screen on the storyboard, but it looks fine(outside of my second issue) in the Assistant editor.
My second issue is that on some phone sizes the constraints are causing the text fields to expand when viewed in the Assistant editor and on an iPhone 6s test device.
I've added some screen shots below. Any help with this issue would be really appreciated.
Each time you add a constraint in storyboard, it is not automatically applied to your working view. You may think it should be applied immediately, but try to think think like this. If you have a view, and you apply height constraint (for example) and if Xcode applied it automatically you would get a view of width 0, since you haven't applied width constraint. That's why you need to tell Xcode to update constraints explicitly.
So when you want to update constraints, select view you want to update and go to Resolve Auto Layout issues, and click on Update Frames. This is located in the bottom right corner of your storyboard. It looks like a small triangle between two lines. Here you can update all views or just selected views.
For the second issue, you need to apply fixed width constraint to your stack view, instead of adding leading and trailing constraints. By doing that stack view will have the same width on each device.

How to Align Everything to Centre Xcode

I am trying to align all items to centre in Xcode as you can see here but the problem is it looks un aligned in the other views
I have tried to do this using constraints but these do not seem to make any difference after updating frames.
All I am trying to achieve is for everything shown to be centred across all devices.
Thanks.
You can simply pin them using the horizontal center in container constraint in Storyboard.
Select all your views and assign it here:
I aligned Horizontal and Vertical centre in container from the Editor -> Align menu and then added constraints using the constraints editor for Height and Size. I also setup some top constraints (using I bars in constraints editor) so the items below my image all lined up with it correctly.
For more info, watch this Youtube video provided by Lennet.

Resources