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!
- Auto Layout with relative constraints not affecting systemLayoutSizeFittingSize: for UITableViewCell
- UIScrollView animation of height and contentOffset “jumps” content from bottom
- how can I use one storyboard for 4“ and 3.5” iphone screens with autolayout (ios6 + ios7)?
- Remove all constraints affecting a UIView
- Getting a “This application is modifying the autolayout engine from a background thread” error?
- Animating with UIDynamicAnimator when Autolayout is in play
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.
- email from Apple – “Missing Push Notification Entitlement”
- Shared Library for iPhone and BlackBerry
- How to hide status bar with animation in iOS 7?
- viewDidLayoutSubviews is called when label changes (xcode) (swift)
- How to set animation to UIImageView?
- Add rows to UITableView when scrolled to bottom
- Understanding iBeacon data : the power field and other bytes
- Your session has expired. Please log in, Xcode 8.2 giving this error while adding account
- UITextView issue with ActionSheetStringPicker Picker view
- How can I get the console logs from the iOS Simulator?
- What does “Receiver type 'CALayer' for instance message is a forward declaration” mean here?
- Swift – Firebase search in database
- Can I create or use the view controller like SLComposeViewController for the social networks other than Twitter and Facebook
- iPhone Linker Error (AudioStreamer)
- Twitter – how to get user's timeline