How to figure out dimensions of image to use from Storyboard? - ios

I have a UIImageView in a screen in my Storyboard. From the Dimensions of the image in the Storyboard, what size image should I exporting from my photo editor (like Illustrator) so that the image does not look bad / stretch / out of proportion?
iOS Noob here -- trying to figure out what dimensions of the image to request from my designer.

If the imageView is constrained so its size never changes, you can just find the size of the view in the size inspector and use that. If the imageView or image shape might change, you can set the imageView to Aspect Fit or apply constraints that allow different aspect ratios.

Related

Make UIImageView fit width of screen but keep aspect ratio [swift]

I'm trying to build a simple tableview with a tableView showing a list of images people posted and comments their friends added.
This is a subclass of TableViewCell, and I used stack views to lay it out. The problem is that I want to show the photos without stretching them - I want them to keep their original aspect ratio, but people can upload images of any dimensions. You see in the screenshot that the image is squished.
What I noticed is that the larger the uploaded .jpeg file, the taller the cells grew (I'm guessing the image size is dictating the intrinsic height?), but since the width can't change, each image is squished differently. A huge picture will show up super tall but with the same width.
I tried setting the image to Aspect Fit, but only the visible image itself does what I want: fit to width and not warp the aspect ratio. However, the UIImageView itself is still super tall and pushing all other UI elements out of the way.
I must be missing something here... It shouldn't be so hard, should it?
To constraint the image as aspect ratio , first give it width of screen , then give it a static height in IB and hook that constraint as IBOutlet
and set it inside cellForRow
cell.imageHeightcon.constant = imageRealHeight*imageWidthInIB/imageRealWidth
You should fix the size of the image view for whatever you want. Then you should use aspect to fill instead of aspect to fit and select the option clip to bounds in the attribute inspection

Swift: is possible to get the default size of UIImageView used by UIImagePickerController?

In my iOS app I am developing, it is necessary for the user to take a photo. As you can see from the following image
by default, when we take a photo with iOS camera app, then it is showed with a standard/default size (the one delimited by those 8 pins) and I would like my app to be the same. So, which size should I set my UIImageView into which the photo will be displayed? How can I get that default size in Swift?
Or maybe...which would be the best size to give to UIImageview to prevent the photo from being deformed too much?
Thank you very much for you attention
UIImage has a property called size which specifies width and height of the image. So you could size your UIImageView to those.
Alternatively, if you're using constraints or autoresize mask (flexible width, flexible height) simply don't set a size and the UIImageView will fill itself according to contentMode.
You must understand however that what you see in the image you posted is not the "original size" of the image. Someone decided that the UIImageView should be place at X distance from top and bottom margins, thus forcing an implicit size on the UIImageView

Can't get UIImageView to resize to fit screen

I've got an image which I want to display in a UIImageView and want it to automatically resize to fit the view, and fit the screen size of the device (iPhone 4, 6, and 6+ sizes).
However I've set the view mode of the UIImageView and its parent UIView to be AspectFit but the image doesn't scale to fit the view. Why does the image not shrink to fit within the UIImageView even though the view mode is set to AspectFit?
(I"m using Xcode 6)
Both aspect fill and aspect fit are used to size the image view to the size of the photo inside of it.
Aspect fit sizes your image so that the whole thing fits within the bounds of your image view.
Aspect fill sizes your image so that it fills up the whole image view (which can result in clipping).
More info on those definitions here.
What you most likely want to do is manually size your image view to fit the screen. The easiest way to do this might be to use something like the following, that way it will size to whatever device you're using.
[self.myImageView setFrame:self.view.bounds];

UIImageView Aspect Ratio?

I have an image of size 320X460 and I want to create an UIImageView which height should be 450. To maintain aspect ratio I calculated the width of UIImageView = (320/460)*450 = 313.043 dynamically. And set the contentMode For UIImageView is UIViewContentModeScaleAspectFit. And set the image(320x460) to image view but it is some what blur.
Note: If I don't resize the UIImageView to 313.043X450 the image is very clear as it is. So what is the mistake I have done?
If I understand the question, this should answer it.
First to set the aspect ratio for the image in your image view.
myView.contentMode = .scaleAspectFit
Next, your image may blur because it is a .png or another rasterized format. You need to use .pdf as recommended by Apple or at very least another vectorized format. Rasterized images have values for all pixels in the image, so when the image is stretched too far it just duplicates and blurs pixels. Vectorized images do not blur because they are really just a series of instructions on how to draw/render the corresponding image.
If you are resizing UIImageView manually, set the content mode to UIViewContentModeScaleAspectFill.
If you want to keep content mode UIViewContentModeScaleAspectFit do not resize imageview to 313. Image will adjust maximum possible width and height , keeping it's aspect ratio.

Zoom image until it fits ImageView Completely

I have a simple UIImageView and an image. I want to fit the image in that UIImageView but I don't want the image aspect ratio to change and I also don't want any dead spaces. ( black bars on the sides etc') I don't care if the image is zoomed in all the way as long as those 2 rules are applied.
Is there a build in setting for that? I tried all the Scale To Fill and Aspect Fill etc' but couldn't find what I'm looking for.
For example: UIImageView is 300x300
image is 200x250. The image will zoom in until all the areas of the UIImageView are filled.
For a UIImageView you can use Aspect Fill in the properties to do this.
But you may have to tick the box "Clip Subviews" otherwise the image will spill outside the image view frame.

Resources