views:

492

answers:

1

previously i had custom tableviewcell and was loading from Nib.in that i have specified mode "Aspect to fit" for my imageview. but loading this Nib file was too slow. so i have started drawing content of uitablewviewcell. here is a code for what i am doing to draw image.

[image drawInRect:CGRectMake(10,10,80,100)];

but this does not give me same effect what i had in my Nib file. that is "Aspect to fit". image looks starched.so my question is how to achieve "Aspect to fit" mode using this code.

Thanks.

A: 

If the image has the correct size (i.e., you don't need to scale it to fit into the drawing area), you can use

[image drawAtPoint:CGPointMake(10, 10)];

(or calculate the point differently if you want to center it).

Otherwise, you'll have to calculate a rect with the correct aspect ratio yourself.

Ole Begemann