Swift image Aspect Fill for tall image not working - swift

I have this UIImageView which may contain images with different ratios.
I have studied the properties of UIImageView and it seems that the Aspect Fill property set for the Mode of the View should be what I need.
It works as intended when the image is wider than taller: cuts the left and right parts of the image out of the UIImageView.
However if the image is taller than wider it does not cut the above and below part of the image, it allows the image to come out of its view and overlap below views.
These are the constraints I have for the UIImageView:
I have seen several tutorials proceeding like I do, but the result is different for me.

If the image is fitting correctly, but is extending outside the bounds of the image view, try turning on "clip subviews"

For such condition , Two possible solution may help :
Calculate aspect ratio based on your required dimension so that picture quality remains intact . ( ** use Aspect Fit calculator to find required ratio)
CENTER OR ASPECT FIT attributs of Imageview
Thanks

Related

Set Constraints of Image using XCode 11

I'm trying to constraint one dog image so that it is centered vertically in the container, which I can do. What I can't seem to get it is having it just above the halfway horizontal point. So I want it to be a certain fraction down the screen (say a third) on any device. I also want the size of the image to be relative to the screen size.
I want the image to be about what it is in the image but maintain its proportions relative to the device of the user.
I've tried tons of things and none of them work. Any help is appreciated.
Here's the Image
Create an UIView and set the image to fill the UIView. After that make the UIView top constrain equal to the centerY anchor which makes the UIView below center horizantal. By using layout anchors for width and height ( not fixed hard coded numbers) you will make it's size relative to device size so doesn't matter using any device type. Post a graphical design if you need more specific answer.

Image aspect ratio swift ios

So, I'm learning iOS Swift. I'm going by some tutorials, and I'm stucked at image positioning.
I'm trying to figure out how uploaded picture is rescaled and positioned.Since I cannot post the screenshot, image that should be shown in my simulator as whole, I can only see like 25% of the picture. Should I change something in Attributes or in Size Inspector?
What I did so far (clearly wrong), was setting Intrinsic Size field -> select Placeholder, w/h = 320.
Then, I pinned and selected Aspect Ratio.
Any help, please?
Thanks.
If you're asking how to make sure an image fills a UIImageView:
myImageView.contentMode = UIViewContentMode.ScaleAspectFill
You may also need to set constraints if you placed your image view in interface builder.
It's not entirely clear from your question how you want it positioned, but hopefully these get you on the right path.

AutoLayout to adjust image size proportional to 50%

I have read this post and I have tried with many examples but i could not put two images one beside the other, each one with a width 50% and at the same time that this images maintain their aspect ratio. I do not understand what restrictions need to.
I have this:
In the image you can see the viewcontroller structure, 2 imageview and the constraints.
Please I need help, at least one similar example. Thanks.
I can see you have missing constraints on your scene, so that could be an issue.
I would put the UIImageViews in a container view pinned to your main view, making sure there are no missing constraints. The benefit of this is in debugging - you can give it a different BG colour and make sure it's resizing itself properly on the simulator/device. I found that putting the image views inside this helps enormously.
Then you need to specify Aspect Ratio constraints on your image views, and also make them equal widths and heights. Add some small constant horizontal spacing between your image views and top/leading/trailing to the container view, and let auto-layout decide the optimal image sizes.
I've included a screenshot of my storyboard:-
This renders like so:-

How to achieve dynamic UIView masking?

I'm trying to achieve a sort of dynamic UIView masking effect. Here is a sketch:
So as you can see, I'm trying to create a UIView that can effectively cut through an image to reveal the image behind it. I already know how to return an image with a mask statically, however I would like the "revealer" to be draggable (I'll use pan gesture) and live.
Does anyone have any ideas or starting points on how to achieve this? Thanks
(NOTE: My demo says White layer, but I'd actually like to show another image or photo).
masking an image is not that difficult.
This link shows the basics.
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
But personally I think i would make 2 UIImage views and crop the content of the draggable UIView. I'm not sure but I would expect that clipping and panning the second image will be less computationally expensive then applying the mask and will get you a better frame rate.
So I would do: UIImageView of the full image. A UIView on top of it with a white and some transparency setting to make it look white, then a UIImageView with the image either places or cropped so that only the correct section is showing.

iPhone - UIButton background image is cut off sometimes

I am using a custom image as the background image for my buttons. I have noticed that the edges of the buttons are cut off sometimes. My buttons vary in size but the behavior doesn't seem to be dependent on the button size. I am creating the buttons programatically. The image I am using is pretty large to cover the entire background.
Can someone please let me know what could be the issue?
More info
Setting the content mode to UIViewContentModeScaleToFill still cuts of the images. Also tried resizing the image but doesn't make a difference.
Thanks.
Did you try setting the button's dimensions to fit exactly the image?
Is the image just cropped or also blurry (cause it's being resized)? Have you toyed around with UIView's contentMode property for the button?
If you did, did you try increasing/decreasing the width or height by a pixel? I sometimes had blurry buttons even though its dimensions were exactly the image's. Adding or removing an extra pixel sometimes helped.
I finally resolved this by creating a 3x3 px image with the background color as the button's color and a 1 px border surrounding the image. Then used the UIImage method stretchableImageWithLeftCapWidth:topCapHeight: to create an image with the desired border size of 1 px.