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.

+2


source to share


3 answers


Sorry for wasting time. It turns out I haven't tried all containment modes. Content Mode of Bottom top seems to be working. This is how I figured it out. Thank you for your help.



+3


source


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

.



0


source


It looks like your image contains transparent areas, at least at the bottom, that off-center the image.

Edit: Also, you have to make sure the image resolution is set to 72dpi.

0


source







All Articles