Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)updateImageViewContent {
- dispatch_async(
- dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- UIImage * img = [UIImage imageNamed:@"background.jpg"];
- dispatch_sync(dispatch_get_main_queue(), ^{
- [[self imageView] setImage:img];
- });
- });
- }
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- if (self.tag == 1) {
- self.backgroundColor= [UIColor redColor];
- }
- else {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self setImage:[UIImage imageNamed:@"woodenTile.jpg"]];
- });
- [UIView animateWithDuration:0.25 animations:
- ^(){[self setFrame:CGRectInset(self.frame, 50, 50)];}];
- }
- }
- NSURL * url = [ [NSBundle mainBundle]URLForResource:@"bois" withExtension:@"jpg"];
- NSURLRequest * request = [NSURLRequest requestWithURL:url];
- [self.imageView setImageWithURLRequest:request
- placeholderImage:[UIImage imageNamed:@"placeholder.png"]
- success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
- NSLog(@"success: %@", NSStringFromCGSize([image size]));
- } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
- NSLog(@"failure: %@", response);
- }];
- // this code works. Used to test that url is valid. But it's blocking the UI as expected.
- if (false)
- if (url) {
- [self.imageView setImage: [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]]; }
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- UIImage * img = [UIImage imageNamed:@"background.jpg"];
- // Make a trivial (1x1) graphics context, and draw the image into it
- UIGraphicsBeginImageContext(CGSizeMake(1,1));
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), [img CGImage]);
- UIGraphicsEndImageContext();
- // Now the image will have been loaded and decoded and is ready to rock for the main thread
- dispatch_sync(dispatch_get_main_queue(), ^{
- [[self imageView] setImage: img];
- });
- });
- longpress.minimumPressDuration = 0.01;
- [YourImageView setImageWithURL:[NSURL URLWithString:@"http://image_to_download_from_serrver.jpg"]
- placeholderImage:[UIImage imageNamed:@"static_local_image.png"]
- success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
- //ON success perform
- }
- failure:NULL];
- -(void)updateImageViewContent {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIImage * img = [UIImage imageNamed:@"background.jpg"];
- [[self imageView] setImage:img];
- });
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [self setImage:[UIImage imageNamed:@"woodenTile.jpg"]];
- });
- [self setImage:[UIImage imageNamed:@"woodenTile.jpg"]];
- FXImageView *imageView = [[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 100.0f, 150.0f)];
- imageView.contentMode = UIViewContentModeScaleAspectFit;
- imageView.asynchronous = YES;
- //show placeholder
- imageView.processedImage = [UIImage imageNamed:@"placeholder.png"];
- //set image with URL. FXImageView will then download and process the image
- [imageView setImageWithContentsOfURL:url];
- #import "UIImageView+AFNetworking.h"
- Use **setImageWithURL** function of AFNetwork....
- queue = dispatch_queue_create("com.myapp.imageProcessingQueue", DISPATCH_QUEUE_SERIAL);**
- or
- queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
- dispatch_async( queue, ^{
- // Load UImage from URL
- // by using ImageWithContentsOfUrl or
- UIImage *imagename = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
- // Then to set the image it must be done on the main thread
- dispatch_sync( dispatch_get_main_queue(), ^{
- [page_cover setImage: imagename];
- imagename = nil;
- });
- });
Add Comment
Please, Sign In to add comment