Center image in LaunchScreen storyboard - ios

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

Related

I can't align this Image View in center of container - 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.

Constraints to be set for x position

I've a scenario where in I've to display four circles. These should be in center of screen. I tried to place x and top constraint but this doesn't works fine for iPhone 4 device.
What constraints should I set so that all four circles should appear in center for all iPhone device?
Further, there is UICollectionView in bottom. I tried to set the top, left, w and height but this didn't worked.
Any solution?
1) Embed your 4 circle in UIView.
2) Set UIView constraint top, fixed width,fixed height and horizontal center
3) Now Select all 4 circle and set constraint like top, leading,trailing,bottom and equal width.

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.

How can I give constraints some margin from the center of superView

I am using auto layout. I have one UIView that takes place at 20px margin from the center of the superview.
Right now I have given the Top Space to superview that i have make in the iPhone 6+ Xib. but when i run in the iPhone 4 simulator it goes to too much down.
Any idea
If you want the view to be placed relative to the center of the superview, you should be using centerX and/or centerY constraints, not a constraint to the top of the superview. In IB, if you choose the "Vertical Center in Container" constraint to center the view vertically, you can edit that constraint to change its constant value which will offset the view from the center by whatever number you choose.

Auto-layout a basic thing [duplicate]

How do I use auto-layout to make a child view fill its parent, or at least anchor all its edges to the parent view's edges?
I am using all four vertical and horizontal constraints in "Spacing to nearest neighbour", but when I run the app on a 3.5" device, the height of the view has not been automatically adjusted from 568 to 480 as expected.
Pin the top space to superview, bottom space to superview, leading space to superview and trailing space to superview.
Then set edit the constraints like so:
Superview.Top >= View.Top and Superview.Bottom >= View.Bottom
I would just set all "Spacing to nearest neighbor" to 0, and align horizontal and vertical center. That should do the trick.

Resources