Set size of UIImageView - swift

I have a very simple question,
I am working in the storyboard and is dragging a uiimageview into the viewcontroller. I configure the imageview to be square (like 100*100). I now set the image to something that has another aspect ratio (like 100*150). When I build the app I expect the imageView to be square (100*100) as i have set in the constraints, but instead it shows the imageView with the image size. So in other words, what I am asking is: How can I set the imageView to the exact size I want so it overwrites the image size? Hope this makes sense, else I can try to explain it a bit better.

Did you set imageView.clipsToBounds = true :)

Related

How do I replace an image in a rotated and scaled UIImageView?

I have a UIView with a UIImageView as a subview. I modify the UIView with CGAffineTransformRotate and CGAffineTransformScale. The UIImageView subview also transforms with it automatically.
I want to replace the UIImage in the UIImageView subview with a new UIImage. When I do this, the image is the wrong size and rotation, because the original been scaled and rotated.
How do I replace the image subview and have it appear as the previous image did (same size/rotation/location)?
Take another UIImageView2 and put your previous image in it first. Then after you scale and modify the original image to a new one and want to see your original one, you can show the UIImageView2 image.
I found the bug, I was removing the original image and didn't know it.
imageView.image = nextImage;
Changing the image as above keeps the scale and rotation from the parent. No trickery involved.

What is the maximum size for a UINavigationBar titleView?

I want to add a logo to the navigation bar on the first view controller, but it scales it badly because I don't know what the maximum size is. Does anyone know?
By the way, I know about the trick for creating full-sized images but I don't want to do that, I just want to utilise the built-in titleView property.
Thanks!
In general, I think that the title view is adjusted to whatever space other views leave left and right. At least that is the behavior of the standard title view.
Have you tried to play with the contentMode property of your UIImageView (which I assume you put into the titleView)? If not, try
imageView.contentMode = UIViewContentModeScaleAspectFit;
and try out a suitable CGRect for the frame. If your image is just large enough for the smallest title view, it should work no matter how wide the title view gets.

UIImageView ignores UIViewContentModeScaleToFill

I have a UIImageView that I dynamically load with an Image using
myTableViewCell.myImageView.image = [UIImage imageNamed:myImageFileName];
myImageView is a UIImageView added to a myTableViewCell.nib and declared as IBOutlet. In IB I set the properties to set the content mode to "ScaleToFill".
The images are larger than the UIImageView and I want to auto-scale them down to the size of the view.
Strangely and whatever I try, this doesn't seem to work (XCode version is 3.2.3).
One Oberservation is that the myTableViewCell.myImageView seems to take it's size from the top cell in the tableview, since the cells below are displayed in equal size to the first cell, even though the image sizes are different.
Note that I use the same myTableViewCell in another tableView with different Icons and there it works. I can't spot the difference between the 2 except the jpg files have different dimensions and aspect ratios ...
Is it possible that the TableView-class has something to do with it?
Are the image properties that prevent the image from resizing?
I found th reason for this. In IB the 'Autosizing' parameters were set to strech the image according to the display size.
Changing these parameters to keep the image at constant size resolve the problem.

iPhone - Center UIImage in UIImageView

I have a UIImageView. I get a UIImage from a URL. The image displays in the UIImageView, but I can't get it to center correctly. The UIImage is 80 x 68 pixels. The UIImaveView's size is 90 x 90. When I display the UIImage in the UIImageView the UIImage is shrunken so that it fits, although it is already smaller than the UIImageView. I have tried all the Content Modes in IB. Some of them shift the image up so that it is no longer in the UIImageView. None of this really makes sense to me. It seems that the UIImage should display inside the UIImageView fine if it is already within the required size. Any help would be great.
With Mode of Center on the UIImageView
alt text http://img406.imageshack.us/img406/3696/screenshot20090915at447.png
With Mode of Aspect Fit on the UIImageView
alt text http://img406.imageshack.us/img406/9373/screenshot20090915at447e.png
With Center, the size of the image seems correct but you can see that it goes out of the UIImageView which has a red UIView underneath it and is actually 2px on each side larger than the image view. But with the Aspect Fit, it makes the image smaller so that it fits inside. But I don't understand why it would make it smaller if it is already small enough to fit.
Sorry for wasting anyone's time. Turns out I didn't try all of the content modes. Seems that Content Mode of Bottom top works. This is backwards from how I understood it. Thanks for all your help.
Try this. Change your UIImageView to be the same size as the UIImage that you are going to load, then position the UIImageView so that it's centered. This is the approach I've taken since I find UIImageView to be a bit funny to work with. Or, if you prefer, skip the UIImageView and just draw the UIImage using it's - (void)drawInRect:(CGRect)rect method.
Sounds like your image contains transparent areas, at least at the bottom, which shift the image off center.
Edit: Also, you should check that the resolution of the image is set to 72dpi.

iPhone - increase UIImageView size and keep the image size fixed

I have a custom UIImageView class which I use to handle multi-touch events on the UIImageView. When the user touch begins, I want to increase the UIImageView's frame but keep the UIImage size fixed.
I tried changing the UIImageView's frame and then calling the drawInRect: method of UIImage to keep the UIImage's size fixed. But this is not working.
The contentMode for the UIImageView is set as ScaleAspectFit and as soon as I increase the frame size of the UIImageView, the UIImage size also increases (and is not affected by the drawInRect:)
Can someone please tell me how I can achieve this?
Thanks.
Adding more details
What I am trying to do is this
Place a UIImageView on the screen with the size same as the size of the image
When the user selects the image, anywhere he touches, the image edits as if the user is doing multi-touch with the image
If I increase the size of the imageview to detect touches any where, the image size also increases... Hope that makes things clearer!
Thanks
There may well be other ways to do it, but I think the UIImageView is doing what it's intended to do here.
What do you want the area of the view not covered by the image to look like? Be transparent? Have a solid colour?
Why do you want to do this? Is it to capture touch events from a wider area than that under the image itself?
If you have a good reason for needing to do this I would create a new view, probably just a plain UIView (with background set to transparent colour), and add the UIImageView to that. Make the plain view the one you resize.
I haven't specifically tried this, but I think it would work:
imageView.contentMode = UIViewContentModeCenter;