I'm using a launch screen xib and I can't get the image within the UIImageView to appear. Currently, I have a UILabel with the imageView placed right below the label and also centered horizontally. I set all the constraints for the imageView but for some reason the label appears but the image doesn't. This is my first time using the whole wAny hAny size classes. Is there something I'm missing?
Based on my recent experience, it appears that as of iOS 8.3, any images in the launch screen XIB have to be in the image assets. I do not know if this is the OP's problem or not, but definitely worth mentioning for other folks coming here with the same issue.
This is happening because of the horizontal space constraints of the imageView, both the leading and trailing space to the superview. Here the launch screen is laid out in the wAny|hAny size class. It could not satisfy the Horizontal space -(196) on a smaller device. So what you can do
Remove the horizontal space constrains(both leading&trailing) of imageView
Add widthconstraint to the imageView or Aspect Ratio could be more appropriate
Other constraints looks fine, top & bottom spacing and centre horizontally in container keep as it is
Related
I am attempting to customize the default LaunchScreen.storyboard of my Flutter app. I simply have a red background on the default View, and I added an Image View as a child of it. This Image View is centered on the screen and renders an image that I have added to "Assets.xcassets" with all 3 sizes. Below is a preview of what my Xcode displays:
However, this storyboard renders differently on devices than it appears in Xcode. For example, it appears slightly off-centered on iPhone 12, and it is scaled up too high for iPhone 6s and is way off-centered. See below for screenshots:
As you can see, the storyboard renders differently on the two devices. How can I make the storyboard appear the same on both devices as it does in Xcode? Any help is appreciated. If I used any incorrect terminology or need to provide additional details, please let me know as I have minimal experience using Xcode.
From the storyboard screenshot attached, it looks like there are no constraints added to the UIImageView.
You should add top, leading, bottom & trailing constraints to superview with 0 spacing to achieve what you want.
UPDATE
Above is applicable to the case when you have a small size image like 100x100 or similar that can easily fit on all screen sizes. In the comments, we see that image is way too big and we want to keep it in center while occupying 50% of screen width.
Remove the leading and trailing constraints, select the imageView and it's superview - add equal widths constraint with a multiplier of 0.5, this will make sure that imageView will always occupy 50% of the superview's width.
Also add horizontally center constraint on the imageView. Make sure imageView Content Mode is set to Aspect Fit.
I have a UIImageView that needs to be centered and have a width that's equal to the screen width and some height that grows proportionally with the width. So for instance, for the iPhoneXR I have:
And on the iPad 9.7 it would be:
So basically the image just scales proportionally with each screen size. I have already figured out how to center it using constraints, but I'm lost on how to get it to scale proportionally. I've played around with the auto resizing options and constraints to no avail. I struggle so badly with these storyboards, wish I could just code it! Is this even possible in a LaunchScreen storyboard?
You can't execute any code inside launch screen. However, you can make it with constraints.
Set center equal to superview, then set width equal to superview. Now, you can add aspectRatio which is like 1:1, so you imageView height would always be equal to its width or any other ratio you want.
Example:
By adding proper constraint you will get your expected result. Add aspectRatio constraint to imageView.
All constraints as per
You can not give constraints to a view w.r.t viewController in LaunchScreen.storyboard because our view hierarchy has not loaded till that point of time.
You can give an imageView constraints w.r.t itself. CTRL drag on the imageView and select height, width or aspect ratio.
Though the recommended way will be to use another viewController that will work as LaunchScreen with some delay in segue.
I drag a vertical UIStackView in my storyboard, I constrain it vertically and horizontally and give it fixed dimensions, 300x300.
Inside this stackview, I put:
a UIImageView (Aspect Fit)
an horizontal stackview containing two buttons
I have no problems if I equally space the content inside the main stackview, but it's not what I want.
I want the imageview to take 70% of the vertical space, leaving the other 30% to the buttons.
I tried using Fill proportionally on the main stackview, but, while in the storyboard is anything ok, when I test on simulator the two buttons totally disappear and I only see the imageview with its content.
What am I doing wrong?
I've recorded a short video
Basically you need to set the height of the image to be equal to 70% of the stackview height. Hope it'd help
I've been working on an app page in the iPhone 7 view of the latest version of Xcode. I got everything working and looking well and then when I went to the iPad view, everything was stretched out and looked awful. I reseted the auto layout and added different constraints and nothing will work. The bigger the screen is, the more stretched out some of the images become, while other are perfectly good. What am I doing wrong and what can I do to fix this issue?
If your requirement is to keep the image in the middle I suggest that you don't use any of the pin constraints. Instead select the align constraints and align the image vertically/horizontally in the view.
What's happening here is that the images are pinned to the edges of the view and when you choose a wider device the images are stretched so as to maintain the pin constraints. That's not what you would want to do.
Hope this helps.
You might want to set the Content Mode of your ImageViews to Aspect Fit:
An Aspect Ratio Constraint is not needed. A Leading, Top and Center Constraint should be enough.
Add Aspect Ratio.connect image to view aspect ratio.next add the align constraints and align the image vertically/horizontally in the view.
I am running into an issue regarding auto layout with constraints. I am trying to keep my image evenly distant from the edges of my UIView. This isn't working for me and need some help regarding it.
Here are the images I took from my simulator. You can see the iPhone image(bottom image) has more spacing between the image and the edge of the view.
you can set the constraints of UIImageView as Top space to UIView,LeadingSpace to UIView,TrailingSpace to UIView, And set the UIImageView Hight constraint as much you want .And also put the UIImage content mode is aspect to Fill or Fit .Remember to put the Top,Left,Right Constraint value as a standard (e.g:8 points).