Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>//JImage.h #import &lt;Foundation/Foundation.h&gt; @interface JImage : UIImageView { NSURLConnection *connection; NSMutableData* data; UIActivityIndicatorView *ai; } -(void)initWithImageAtURL:(NSURL*)url; @property (nonatomic, retain) NSURLConnection *connection; @property (nonatomic, retain) NSMutableData* data; @property (nonatomic, retain) UIActivityIndicatorView *ai; @end //JImage.m #import "JImage.h" @implementation JImage @synthesize ai,connection, data; -(void)initWithImageAtURL:(NSURL*)url { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [self setContentMode:UIViewContentModeScaleToFill]; if (!ai){ [self setAi:[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]]; [ai startAnimating]; [ai setFrame:CGRectMake(27.5, 27.5, 20, 20)]; [ai setColor:[UIColor blackColor]]; [self addSubview:ai]; } NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; } - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData { if (data==nil) data = [[NSMutableData alloc] initWithCapacity:5000]; [data appendData:incrementalData]; NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[data length]]; NSLog(@"resourceData length: %d", [resourceLength intValue]); } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"Connection error..."); [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [ai removeFromSuperview]; } - (void)connectionDidFinishLoading:(NSURLConnection*)theConnection { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [self setImage:[UIImage imageWithData: data]]; [ai removeFromSuperview]; } @end //Include the definition in your class where you want to use the image -(UIImageView*)downloadImage:(NSURL*)url:(CGRect)frame { JImage *photoImage=[[JImage alloc] init]; photoImage.backgroundColor = [UIColor clearColor]; [photoImage setFrame:frame]; [photoImage setContentMode:UIViewContentModeScaleToFill]; [photoImage initWithImageAtURL:url]; return photoImage; } //How to call the class UIImageView *imagV=[self downloadImage:url :rect]; //you can call the downloadImage function in looping statement and subview the returned imageview. //it will help you in lazy loading of images. //Hope this will help </code></pre>
    singulars
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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