How to make iOS ImageView full match window? - ios

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).

Related

How to make splash screen fit for both landscape and portrait in ios

I'm making a splash screen, but problem is, when i change to landscape , it will not fit the screen, so, how can i fix this
Here is on portrait mode:
And when switch to landscape:
So how to fix this? Thank you guy a lots
So, the first thing I do is seperate the background from the logo. As a "general" rule of thumb (for me) I try and keep the logo within about 300x300 (# x1), but you could also make constrain the width and/or height the logo to the view's width/height. Applying a ratio constraint would also allow you to scale the logo as a percentage of the view, while maintaining its aspect ratio (or just use "Aspect Fit" on the UIImageView), but every splash screen seems to want to be slightly different.
I drop a UIImageView onto the launch view and, making sure to turn off "Constrain to Margin" and ensure I'm referencing the UIView and not the "Safe Area", pin it to all the edges
I then assign the image I want to use as the background to UIImageView and select "Aspect Fill" to ensure that the aspect ratio is maintained, but it will fill (or overflow) all the available area of the image view
Next, I add another UIImageView. Here I setup the sizing constraints for the image. In my case, I made a square logo of 300x300px so I don't need to mess about with it and the constrain it to be centred in the launch view
Then I apply the logo image I want to use and ensure the UIImageView is set to "Aspect Fit" (which is now default for Xcode 11+)
Also note that I've offset the UIImageView's vertical position so it's slightly offset from the middle, don't ask me why, but it looks weird been in the middle.
You can then use the storyboard editor to explore the various devices and orientations
You could also explore things like "size class" so you could customise how the layout changes between different device "size classes", but I think that would be overkill for something like this

LaunchScreen.storyboard appearing differently on devices than in Xcode?

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.

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

How to use auto-layout to put things in a percentage of a screen size IOS

So I am trying to make my launch screen for an app. The launch screen is made up of 2 text boxes and 2 UIImageViews.
This is my sketch up of what it will look like
My problem is I can not get auto layout to work with percentages of the screen, instead it has these numbers that I dont quite know what to do with. So while I know that the two image views are a 4th of the screen width from the edges I dont know how to put it their. Also I dont know how to make the image size occupy the same ratio of space on all devices.
Could you please get me started on setting this up?
autolayout does not Have Percentage support but it supports Aspect Ratio.
you need to add one view and add your two imageViews and textFields add equal width and height constraint for ImageViews and same for TextField
you can also add constraints to ImageView to expand in rest of space for that just add margin constraints and equal width and Height of ImageViews.
add aspect Ratio to ImageView's Width and SuperViews width as your requirement.
you can add aspect Ratio with individually to width and Height.
here as you mentioned in que. you can add aspect ration 4:1 for 4th of the screen size.
do same for TextField.
if you still need help than tell me I can explain in depth with screenshot.

UIButton background image not sizing right with autolayout?

I'm simply trying to fill the entire width of an iPhone screen with a login button for my users that is basically an image set as the background of a UIButton. This is the result I end up with (Notice it fills width as intended, but shrunken down in height):
My thought process was to make 3 images to compensate for #1x #2x #3x resolutions with different image sizes?
#1x: 144x33px
#2x: 288x65
#3x: 432x97
Now from there I thought I could just fill the width of my ViewController with the UIButton in Storyboard and set the background image of the UIButton which I would think would use the proper one automatically depending on device considering I put them in the right spots in Images.xcassets. I also set the trailing and leading constraints as well as bottom constraint to keep it filling left to right and stick to bottom. I just don't get how I would fix the height issue if it's looking fine in the actual XCode storyboard, but not in the preview or simulator as seen in above photo.
Any help would be tremendously appreciated.
The different image sizes are not used to replace each other when you scale an image. They are used to look nice when there are more actual pixels than software pixels.
For your purposes, you probably want to scale the image with the stretching rules or cap insets.
Check out this answer for an example:
https://stackoverflow.com/a/13367861/1864591

Resources