I can't align this Image View in center of container - iOS - ios

See the image below
I really need align this view in the center of the container.. (StackView) !!
To align the StackView a use Constraints Top 20 right and left 10 only it..
And I'm trying to align this image view at the center of the container but I don't know how I can do it.

Remove the left constraint , drag from the stackView to the superView and select center Horizontally from the popup and click AddConstraints
Or
click the left constraint and edit it to centerX , then set constant = 0

If in attribute inspector, you put alignment for Stackview to "center", it should be in the center. Also, give the image width and hight.

Related

How to use auto layout for a label in interface builder

How would I go about setting constraints for my price label to stay on the side of the screen? Below Is a picture of what I want my tableviews to look like on all iPhones.
http://imgur.com/a/g6PhL
It's easy to do:
1)first add left label
2)ctrl + drag the left label to cell content, and choose Center Vertically in Container:
3)Click Add New Constraints in the right bottom of interface builder,
deselect the Constraint to margins, and click the left dotted line and set the left margin value , eg:8
4) As the same to left label, you can set constraints to your right label, and the different is only you should set right margin nor left margin , in there I omit the Vertically in Container step of right label, you can see 2):
EDIT
as matt's advice, you better set the right label's alignment to right;
The blue label is on the right and needs to stay on the right. It is sized automatically by its content. So just pin its right edge to the right of its superview and its top or bottom (not both) to the top or bottom of its superview.

Multiple buttons at center of screen vertically with Autolayout in iOS

I want to add 3 buttons with same height and same width at the center of screen vertically. I am using auto layout.
I tried by selecting all buttons and set the constraint to align center vertically, but it's not working.
1 select the Button2 give hive constraints like first image.see the constraints window.
2 give the constraints to butto1.
3 give the constraints to butto3.
you can see all there button constraints in window.
try this constraint:
Step: 1>
Step: 2>
Step: 3>
add your buttons in UIView and set top,leading,trailing and fixed height constraints to every button. set constraint for views like center Y (vertically in container), center X (horizontally in container), fixed width,fixed height. make sure that your view's height is not more than it fits all buttons with padding between them.

Center image in LaunchScreen storyboard

I have an imageView in my LaunchScreen.storyboard. I centered it with two constraints:
Center Horizontally (Align Center Y)
Center Vertically (Align Center X)
I also have:
Width constraint equal to 84
What happens is that the image is just below the center. It's not perfectly centered.
Any suggestions?
Thanks!!
Give constraint as below:
1) Top space to superview
2) Bottom space to superview
3) Leading to superview
4) Trailing to superview
This will fill the whole nib with an imageview
One easy way to do it is to add constraints on each side that are equal to the one on their opposite side to center your image. I recently did it to center a label between another label and the the remaining 3 edges of the view

XCode 7 Autolayout Constraints: How to make 2 images stay horizontally in the center

I'm trying to position 2 UIImage views in the center of the screen, side by side. If it's just 1 UIImage, I can just set them to be vertically and horizontally center in the container. If I have 2 UIImage views side by side, I can only set it to be vertically centered, but not horizontally centered since both UIImage views would stack over each other..
Could someone please guide me ? Thanks and greatly appreciated!
Take a view, put both the images inside that view. Add the constraints on those images with respect to the view you made (Edge to edge to the view). Now add the constraints on the view in respect of the super view. (Center vertically and horizontally). That's it!
An elegant way to solve this is to apply constraints on UIImageView itself.
Now think that if you need to have both the image views in superview's centre then one imageView should have it's trailing edge at the centre of superview and another should have a leading edge at the centre.
Control-Click on imgvLeft and drag it to superview, you will see some constraint option to select; choose trailing edge constraint. Now go to that constraint and click it you will see details as shown in picture below. Change the second item from trailing to centreX and keep the constant 0.
Same way you can apply the leading constraint on imgvRight and change the second item to centreX.
Now if you wish to keep some distance between both the views then you can change the constant value in constraints. For example if you need an spacing of 20 px then change the constant to spacing/2 i.e. 10.

auto layout stretching image issue

I'm trying to stretch an image from the very left of the view to the very center. I tried pinning constraints using left 0, bottom 0, and right 300, but it doesn't exactly goto the center. Any ideas?
Assuming that you know how to set the left, top, bottom, height constraints I will explain you how to set the right constraint, which will cause the imageView to span from the left to the center of the screen. Setting any width constraint will not work, because the width depends is different on every device.
click your imageView
choose Align -> Horizontally center in container
click on the newly created constraint
choose the Size Inspector
Change the First Item from Center X to Trailing
The "standard" Horizontally center in container causes the Center X of your view and its super view to be aligned. If you change the First Item to Trailing instead of Center X you therefore align the trailing edge / right of your view to the centerX of your superview.

Resources