I have a rather complicated workflow that is encountering issues on the retina display. I have a scrollview that can consist of up to 19 subviews. Each one of these subviews is composited of several different components (several UILabels, a UIImageView, and some UIButtons). There are multiple scrollviews on screen at any given time, with the potential of hundreds of total subviews. To save on overhead, I create each subview in memory, then flatten it to a UIImage, still in memory. From there I use the UIImage as the subview to display.
As another cost saving step, I decided to save these UIImages out to disk after they were composited, store the path in core data, and pull them off of disk in lieu of recreating them all the time. So, first I check on disk to see if an image for that article is present. If not, I create it, save it to disk, and display it on screen.
Here are the steps I am taking to accomplish this:
// create ViewController (cut initialization code for brevity)
TileViewController *tile = [[TileViewController alloc] init];
// Figure out if working on Retina enabled device
static CGFloat scale = -1.0;
if(scale < 0.0){
UIScreen *screen = [UIScreen mainScreen];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) {
scale = [screen scale];
}else{
scale = 0.0;
}
}
if(scale>0.0){
UIGraphicsBeginImageContextWithOptions(tile.view.bounds.size, NO, scale);
}else{
UIGraphicsBeginImageContext(tile.view.bounds.size);
}
[tile.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
NSString *savePath = <create save path here>;
// Snipped out the code that saves this path to the core data store =
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:savePath
contents:imageData
attributes:nil];
From this point, I use the UIImage in an UIImageView and it gets placed on screen. On first run, when being displayed from memory, it looks great. The second time around, I am pulling the same image from disk using the following code:
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:article.tileImagePath]) {
UIImage *image = [UIImage imageWithContentsOfFile:article.tileImagePath];
// send image to UIImageView
}
The problem is that on the times when the image is not generated, but is pulled from file, the text in the UILabels appears very blurry on the retina display. I can look at the generated images on disk by running this in the simulator and viewing them in the finder on the mac, and they appear crisp and are properly sized (2 times scale).
Is there an additional step I should be taking here?