Quantcast
Channel: Code and Programming » Search Results » table
Viewing all articles
Browse latest Browse all 10

UITableViewCell with UIImage scaling performance

$
0
0

The UITableViewCell has UIImage to be displayed within it.

Images are obtained from the server, and stored in NSDictionary as NSData.

This image is resized for non-retina devices using UIImageGraphicsBeginImageContext as listed below.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellID=@”Cell”;
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
NSDictionary *myDictionary=[self.tableObject objectAtIndex:indexPath.row];
NSData *imgData=[myDictionary objectForKey:@"icon"];
UIImage *img=[UIImage imageWithData:imgData];
if(isRetina]){
cell.iconImageView.image=img;
}else{
CGRect imgRect=CGRectMake(0, 0, img.size.width/2.0, img.size.height/2.0);
UIGraphicsBeginImageContext(imgRect.size);
[img drawInRect:imgRect];
UIImage *newImg=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.iconImageView.image=newImg;
}
}

Would it be better approach and less memory intensive or should store it in the disk, and then access the image from it and assign it to cell.iconImageView.image;


Viewing all articles
Browse latest Browse all 10

Trending Articles