iOS Some UIImageView being stretched - ios

This seems like a silly question, but I have a UITableView and each row has a UIImageView with a dimension of 80x80. The actual content of the image is either 80x80 or 80x64. I recently added some new 80x64 images and the heights of those are being stretched whereas the old 80x64 images are not (they are simply centered within the 80x80 frame).
I vaguely remember setting some kine of xattr on my images a while back, but I can't seem to find what it was. Would this have something to do with my new images being stretched vertically?

You might want to look at the contentMode for your image view, specifically try UIViewContentModeScaleAspectFit. I notice this, especially, when I set image properties for UITableViewCell cells asynchronously. But if I have the routine that is setting the image to also set the contentMode, and all is well.

Related

scale type or contentMode of Image in UIButton is not working

I was trying to put an image in UIButton and the image would fill up the space keeping the aspect ratio intact. I was not able to apply the content mode. Please see the screenshot
I also tried from the code and it's not working as well
myButton.imageView?.contentMode = .scaleAspectFill
By changing the alignment, the image takes the whole space but it does not keep the aspect ratio and content mode does not work as well.
What's causing your problem is how small the image is. There are two things you can do. One option is to set the image you have now as the background image and then change the button's constraints to get the proportions right. You won't be able to have the button be the size you have it now, though, because the image will be all stretched out.
The other thing you could do is find a bigger or different image of that symbol (square.and.arrow), rather than using the one already loaded into Xcode.

iOS Image Resizing / Dealing With Blank Space

I have simply dragged UIImageView into storyboard and made it square. I added a pink background to show the effects of the leftover space in the ImageView. In each case I added either a taller image (1st image) and a wider image (2nd image), as well as a text label. Here are my results.
So the obvious question is....how can I get rid of this extra (pink) space and keep the integrity of the photo (that is, to not have to stretch or lose part of the image)? If I wanted to be able to scroll through photos, it would be nice to have them all the same width to the edge so they look neat and orderly (if they were portrait), and if I wanted to have text under each, I'd want the text to be closer to it, rather than have all the blank (pink) space in between if it were landscape. And obviously different size images will give different sizes of blank space.
So I'm thinking what I could do is before displaying the image, get the size of it, then just have a designated distance from either the label or the edge of screen, depending on the orientation of the picture, and then creating/changing the size of the UIImageView with a bit of math and using the image dimensions before inserting the picture into the ImageView. Is this possible? Is there another method I can't quite figure out?
Just look at any decent photo app and they are nice and neatly organized/displayed despite being different sizes, orientations, etc and I'm wondering how to pull this off. I obviously haven't gotten too deep into using images past simply showing them in a pre-determined ImageView.
Thanks for the help/suggestions!
Try this... set your UIImageView to AspectFit (not AspectFill since that will lose some of the image) and using constraints do the following:
centre the UIImageView in the container both horizontally and vertically
set the UILabel to float below the UIImageView by whatever distance you desire ("standard" is usually good)
set the left, right, and top constraints on the UIImageView to be >= whatever distance you desire
set the bottom constraint on the UILabel to be (once again) >= whatever distance you desire
The effect of this should be that the UIImageView will properly resize itself to its intrinsic size and the constraints should properly position it and the label.

UIImage being stretched when copying from UIPasteboard

I have a valid image with the right content size, however I have noticed when I try to paste this image to WhatsApp or through iMessage the image get's significantly stretched. I have looked at the image and it seams to be fine on UIImageview, but somehow it gets stretched in particular to outer controls.
Is there anyway to fix this issue?
When copying an image make sure to modify the imageView's mode. There are different modes, like Aspect Fit, Scale to fill and so on.
If let's say the image is 500x300 and your imageView's size is set to 350x230 and mode to Scale to fill, it will end up stretched. Try to fiddle around and see what works for you. Most of the times i choose Aspect Fit.
Try that out.
BTW. You can find it under inspection tab in design editor or set it programmatically if you choose so.

resizableImageWithCapInsets in iOS 4

I need to create table cells with a very complicated background image for each: http://i.stack.imgur.com/PBL0S.png
There is a transparent circle in the center of it. And height of my cell depends from its content - it may vary. But I need this circle to always be in the center of background image and have a constant size.
My solution is: cut the image along for 2 parts and then, using the method resizableImageWithCapInsets: create two UIImageView's and locate them one below the other. There is the problem: this method is only availible since iOS 5, but my app needs to run under iOS 4.3. Unfortunatelly, I can't use method stretchableImageWithLeftCapWidth:topCapHeight: because top and bottom caps on my half-images obtained with different heights.
Please, help me to create the method with the same functionality resizableImageWithCapInsets: Or, if there is any better solution, tell it to me, please.
The straight-forward approach can involve three imageviews:
top imageview: stretchable image with the top part of your tag image
center imageview: non-stretchable fixed size image with the center part of your tag image including the white hole
bottom imageview: stretchable image with the bottom part of your tag image
subclass UITableViewCell and override layoutSubviews such that the top image view are always the same size and the center image view preserves its size and center position.
EDIT:
You can also use the stretchableImageWithLeftCapWidth:topCapHeight: method with different cap heights for different images. I don't see a reason why your approach should not work as well.

Scale to fit cuts image

I have an UIImageView with the image of a gradient with a thin line at the bottom. As the image isn't the same size as the imageview I want to scale it in some way. I don't care if I stretch the image but I would like the line at the bottom to be visible. Therefore I chose "Scale To Fill". But as you can see on the second screenshot the bottom line is not showing up in the simulator.
I thought that "Scale to fill" meant that the image got stretched so that all content is visible but that doesn't seem to be the case.
I highly appreciate your answers!
As the image isn't the same size as the imageview I want to scale it in some way. I don't care if I stretch the image
So use a resizable image (resizableImageWithCapInsets:). This is exactly what it is for.
but I would like the line at the bottom to be visible.
Well, there are some extra complications here, and you are not explaining how you are handling them. You have a UIImageView; it has a size. Perhaps it is bigger than the view we are seeing in the screen shot. Perhaps it is being overlapped by the text view that we see below it. In other words, it matters how this image view is being placed in the interface and sized.

Resources