Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I write the code with the help of gcd , you just have to pass the object of imageView and pass the url , it manages all the things, like cache.</p> <pre><code>-(void)downloadingServerImageFromUrl:(UIImageView*)imgView AndUrl:(NSString*)strUrl{ strUrl = [strUrl encodeUrl]; NSString* theFileName = [NSString stringWithFormat:@"%@.png",[[strUrl lastPathComponent] stringByDeletingPathExtension]]; NSFileManager *fileManager =[NSFileManager defaultManager]; NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"tmp/%@",theFileName]]; imgView.backgroundColor = [UIColor darkGrayColor]; UIActivityIndicatorView *actView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; [imgView addSubview:actView]; [actView startAnimating]; CGSize boundsSize = imgView.bounds.size; CGRect frameToCenter = actView.frame; // center horizontally if (frameToCenter.size.width &lt; boundsSize.width) frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2; else frameToCenter.origin.x = 0; // center vertically if (frameToCenter.size.height &lt; boundsSize.height) frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2; else frameToCenter.origin.y = 0; actView.frame = frameToCenter; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ NSData *dataFromFile = nil; NSData *dataFromUrl = nil; dataFromFile = [fileManager contentsAtPath:fileName]; if(dataFromFile==nil){ dataFromUrl=[[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strUrl]] autorelease]; } dispatch_sync(dispatch_get_main_queue(), ^{ if(dataFromFile!=nil){ imgView.image = [UIImage imageWithData:dataFromFile]; }else if(dataFromUrl!=nil){ imgView.image = [UIImage imageWithData:dataFromUrl]; NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"tmp/%@",theFileName]]; BOOL filecreationSuccess = [fileManager createFileAtPath:fileName contents:dataFromUrl attributes:nil]; if(filecreationSuccess == NO){ NSLog(@"Failed to create the html file"); } }else{ imgView.image = [UIImage imageNamed:@"NO_Image.png"]; } [actView removeFromSuperview]; [actView release]; [imgView setBackgroundColor:[UIColor clearColor]]; }); }); </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload