I'm currently trying to show a simple table in my iPhone application, where I use UITableViewCell with the style UITableViewCellStyleValue1 (image on the left, label with label on the right). All cells have a default height (50.0f). Before adding the image to the cell, I resized the image to 40x40, so this is not the total height of the cell (I think it looks ugly).
I am doing this with this code:
cell.imageView.image = [UIImage imageNamed:@"icon.png"]; cell.imageView.image = [RootViewController imageWithImage:cell.imageView.image scaledToSize:CGSizeMake(40, 40)];
It is all very pleasant and works flawlessly. But I want to do this on the iPhone 4 (with a higher resolution screen). The problem is that everything scales seamlessly on the iPhone 4, but the images seem very pixelated.
The reason for this is that everything on the screen is blown up to scale for a new resolution, as well as images, so the images should probably be something like 80x80. But when I resize them to 80x80 (originals 120x120), they look like big, due to scaling.
Is there a way to make my images not full table height, but I want them to be in higher resolution on iPhone 4. Should I create a complete new view for this?
Unfortunately, after the first answer, I realized that my own written function is missing:
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize { UIGraphicsBeginImageContextWithOptions(newSize, NO, [[UIScreen mainScreen] scale]); [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }
As you can see, after the first answer, I tried to get this to work with the UIGraphicsBeginImageContextWithOptions method, but somehow this leads to an empty image.