I am having a hard time understanding how the UIViewContentModeScaleAspectFit works . I am working on app in which i want that the image should be redrawn in such a way that there must be blank area around the image and the image must be set in the center of the image view.
My main concern is that will the UIViewContentModeScaleAspectFit scale image leaving an transparent area around (in every case) or do i need to redraw image programmatically.
If the background of the UIImageView that contains that image is white, then the areas not filled by the image will be white in that view.
Related
I'm trying to pin an image to the top of the screen but I keep getting an extra white extra space at the top. I tried to pin the image relative to the superview instead of the save area but It didn’t work.
image's constraints relative to superview
changing the image's content mode to Scale To Fill solves the issue but it stretches the image.
After changing the image's content mode
You might want to change the contentMode of the UIImageView to either .scaleAspectFit or .scaleAspectFill, whatever fits best your needs.
I have been dealing with this issues for a few days now trying to figure out why images are clipping whenever I pick from the uiimagepicker. I have this button in my view controller that will take on the image that is chosen from the uiimagepicker. The image shows up but there is this weird clipping affect where it shows the entire image but there is this empty space that is black that makes the image look like it is being clipped.
The image of what the issue I am dealing with is below:
image of the current clipping issues
As now, your image view content mode is .fit that's why this is happening, For now, You need to set imageView content mode scaleAspectFill:
imageView.contentMode = UIViewContentMode.scaleAspectFill
imageView.clipsToBounds = true
I've got a background image with a radial gradient, on some views it looks fine.
But on others where I have extra controls at the top of the view its squashed as it has less room to be show.
I guess I'm going to have to take account of the where the images starts at the top or the bottom, so one end will loose a section. But if I can do this via a property, rather than stretch ? or if I have to chop the image some how ?
What can I do?
Are you showing with UIImageView? Default contentmode is set to UIViewContentModeScaleToFill, which is to stretch in all directions to fit frame.
Change contentMode property to get the effect you want, ie UIViewContentModeScaleAspectFill.
I got a UIView subclass that draws a UIImage as its background. The image is created using the stretchableImageWithLeftCapWidth:topCapHeight: method, it has round edges.
I also use an animation block inside of which I resize my view. I had hoped that during animation, the drawRect:method would get called sometimes, which would result in the background image getting drawn correctly.
Unfortunately, the animation seems to render the image and then just rescale it during the animation, which obviously makes the formerly round edges getting nastily stretched.
The only workaround I can imagine is put three separate UIImageViews (top cap, middle fill, bottom cap) above my original background image and then reposition the caps images and scaling the fill image. However, this seems quite complicated...
Is there any better way I can prevent this from happening?
EDIT: Found this. Sounds bad...
While digging through some Apple docs, I coincidentally found the solution to my problem. All you have to do is play with UIView's contentStretch parameter. It allows you to manually specify the area of your view that gets stretched during animation.
I have a simple app that just displays a UIImageView. For some reason the image appears that it is partially transparent as it is much lighter than if I view the same image in photoshop. Any suggestions...I though by default a UIView is opaque.
You have probably changed the alpha of your imageView or the view itself. check for the the transparency of your imageview also. Because the default alpha of the imageview is 1 and opacity is also set to 100%. You might have chane one of these otherwise this is the problem of your image only
I don't believe that UIImageView is by default partially transparent? Try changing the background colour of the application and see if that affects the outcome of your image, if it is transparent it should be darker with a black background rather than white.