IPhone - Center UIImage in UIImageView
I have a UIImageView. I am getting UIImage from url. The image is displayed in the UIImageView, but I cannot center it correctly. UIImage - 80 x 68 pixels. The size of the UIImaveView is 90 x 90. When I display the UIImage in the UIImageView, the UIImage will shrink, so it fits even though it is already smaller than the UIImageView. I have tried all 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 be displayed inside the UIImageView if it is already in the required size. Any help would be great.
In center mode on UIImageView alt text http://img406.imageshack.us/img406/3696/screenshot20090915at447.png
In Aspect Fit mode on UIImageView alt text http://img406.imageshack.us/img406/9373/screenshot20090915at447e.png
With Center, the image appears to be the correct size, but you can see it comes out of the UIImageView with a red UIView underneath and is actually 2px on each side larger than the image. But with Aspect Fit, it shrinks the image to fit inward. But I don't understand why he would shrink it if it is already small enough to fit.
source to share
Try it. Resize yours UIImageView
to the same size as the UIImage
one you are about to upload, then position UIImageView
so that it is centered. This is the approach I have taken since I found UIImageView
it to work a little funny. Or, if you like, skip UIImageView
and just draw UIImage
with the method - (void)drawInRect:(CGRect)rect
.
source to share