LaunchScreen.storyboard appearing differently on devices than in Xcode? - ios

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.

Related

Fixed Button Position Relative to ImageView in Xcode

In my project I would like to essentially 'Pin' a button to a certain position on an image. The imageView scales to the screen size from the centre and maintains its aspect ratio.
I am trying to make it so that each button remains over the chakras "coloured icons in centre of body". I need them to maintain a scale that is the size of the chakras and maintain their position over the chakras regardless of screen size.
Wanted Result
Current Result
Scaling Settings
Aspect Settings
Here's an example - you will want to play with the exact positioning, but this should show you the method. You can do everything using auto layout in Xcode.
I took one of your images, and edited it to remove the buttons, and used it as the image in a UIImageView filling the screen of a UIViewController
Then I created 7 small buttons, and added constraints to them width & height = 20, and Align Centre Y to Image View
The tricky part is to add a constraint to align the centre of each button to a fixed percentage of the UIImageView centre - and that will be trial and error until it looks right.
Here's how to set the constraint
here's the app running on the iPhone 12 simulator
and here it is on an iPad (12.9 inch)
and here in landscape
You can take parent containerView for each imageView and Button.
Please see the picture to this link for better understand.
https://ibb.co/dsTjxbw

Auto Layout Issues Xcode 8

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.

How to make iOS ImageView full match window?

I am new in iOS , I am an android developer self-learing iOS just for fun.
As you can see from the picture , I want to make my ImageView full-displayed in the window in different inch iPhone.
If you are an android developer, you may know what I mean is how to make ImageView match_parent in both width and height?
You must set the UIImageView Constraints, like this to adjust in the full screen, 0 spacing in all sizes, and click in Add 4 Constraints
After that, you must check in the UIImageView settings the mode to Aspect Fit, so it will keep the aspect ratio of your image.
I Took the image from your print, here is the expected final result.
Pin the image view on all four sides to its superview via constraints with a constant of zero. Now configure the image view's content mode so that it doesn't distort the image, but rather keeps its aspect ratio (there are two ways to do this, and I don't know what one you want, so you will have to experiment).

Swift how to resize elements depending on screen size

I've got all my elements in the view and have added constraints to position them correctly on any device.
But when it's run on a 3.5 inch iPhone some of the bottom stuff is cut off and when it's run on a iPhone 6Plus there's a lot of extra space on the bottom.
How could I resize all the elements to look good on all devices?
This is a universal app to run on iPhone and iPad.
I guess you constraint an element as width equals 300...It's very bad for some elements that should fill (or fill percent of) the screen. I suggest you make percentage constraints. For example, make equal width to view, click Edit button and set Multipiler 0.6. It looks like this in storyboard:
make two constraints (trailing and leading for example) and make aspect ratio for your image, maybe this will help you.

launch screen xib not displaying imageview correctly

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

Resources