Loading an image into UIImage asynchronously

I wrote a custom class to do just this, using blocks and GCD: WebImageOperations.h #import <Foundation/Foundation.h> @interface WebImageOperations : NSObject { } // This takes in a string and imagedata object and returns imagedata processed on a background thread + (void)processImageDataWithURLString:(NSString *)urlString andBlock:(void (^)(NSData *imageData))processImage; @end WebImageOperations.m #import “WebImageOperations.h” #import <QuartzCore/QuartzCore.h> @implementation WebImageOperations + (void)processImageDataWithURLString:(NSString … Read more

How to get the displayed image frame from UIImageView?

If it’s UIViewContentModeScaleAspectFit, it’s something like this: UIImageView *iv; // your image view CGSize imageSize = iv.image.size; CGFloat imageScale = fminf(CGRectGetWidth(iv.bounds)/imageSize.width, CGRectGetHeight(iv.bounds)/imageSize.height); CGSize scaledImageSize = CGSizeMake(imageSize.width*imageScale, imageSize.height*imageScale); CGRect imageFrame = CGRectMake(roundf(0.5f*(CGRectGetWidth(iv.bounds)-scaledImageSize.width)), roundf(0.5f*(CGRectGetHeight(iv.bounds)-scaledImageSize.height)), roundf(scaledImageSize.width), roundf(scaledImageSize.height));

UIImageView Touch Event

you can use UITapGestureRecognizer added to the UIImageView via addGestureRecognizer snippets: UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bannerTapped:)]; singleTap.numberOfTapsRequired = 1; singleTap.numberOfTouchesRequired = 1; [iv addGestureRecognizer:singleTap]; [iv setUserInteractionEnabled:YES]; and – (void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer { NSLog(@”%@”, [gestureRecognizer view]); }

Creating a shadow for a UIImageView that has rounded corners?

If you set clipsToBounds to true, this will round the corners but prevent the shadow from appearing. In order to resolve this, you can create two views. The container view should have the shadow, and its subview should have the rounded corners. The container view has clipsToBounds set to false, and has the shadow properties … Read more

Set UIImageView image using a url

For such a straightforward task I would highly recommend against integrating projects such as Three20, the library is a monster and not very straightforward to get up and running. I would instead recommend this approach: NSString *imageUrl = @”http://www.foo.com/myImage.jpg”; [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { myImageView.image = [UIImage … Read more

iPhone: Camera Preview Overlay

For your implementation file: – (IBAction)TakePicture:(id)sender { // Create image picker controller UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; // Set source to the camera imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; // Delegate is self imagePicker.delegate = self; OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; // Insert the overlay: imagePicker.cameraOverlayView = overlay; // Allow editing of image … Read more

With Auto Layout, how do I make a UIImageView’s size dynamic depending on the image?

The image view’s intrinsic size is already dependent on the size of the image. Your assumptions (and constraints are correct). However, if you’ve set up your image view in interface builder and have not provided it with an image, then the layout system (interface builder) won’t know how big your image view is supposed to … Read more