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!
- UITableView within UIScrollView using autolayout
- Adding constraints programmatically in UIScrollView with dynamic buttons - Swift
- What does “Use standard value and Constrain to Margins” mean in Auto Layout?
- iOS >> Dragged View is Jumping Back to Original Position >> Auto Layout Combined with UIPanGestureRecognizer Issue
- Different iPhone devices with single storyboard by using Xcode 8
- xCode 6 beta 7: storyboard adds extra space on right and left sides
2 Solutions Collect From Internet About “XCode 7 Autolayout Constraints: How to make 2 images stay horizontally in the center”
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
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.
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
centreX and keep the constant 0.
Same way you can apply the
leading constraint on
imgvRight and change the
second item to
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.
- How to open Google Maps to show route using Swift
- How to get iOS device MAC address programmatically
- Cannot invoke 'sendAsynchronousRequest' in Swift 2 with an argument list
- Add rows to existing UITableView section
- In new Firebase, how to use multiple config file in xcode?
- Open an application from another (iOS)
- iPhone SDK:How do you play video inside a view? Rather than fullscreen
- Reading an InputStream into a Data object
- Making my function calculate average of array Swift
- BSMachError on granting access to camera
- sound picker / list of system sounds
- Improve HTML5 Canvas frame by frame JPG animation to fully cache before animating
- Http Live Streaming for iPhone and why we use .m3u8 file
- Swift How to change UIAlertController's Title Color
- Appium Error: Could not get Xcode version