UIAlertView + UIImagePosted: October 14, 2010
Today I wanted some debug code to easily display an UIImage to check its orientation. At first I was going to just add it to my main view then remove it after a few seconds, but then realized a modified UIAlertView would be better since it could be displayed fire-and-forget style like
[alert show]; [alert release];, it wouldn’t go away before I had a chance to look, and there could be a title to remind me what I was looking at.
Some trial-and-error was involved to get the message newlines & image position right, but here’s what I came up with. It displays the image scaled to 100 units height.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"\n\n\n\n\n" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; CGFloat imageHeight = 100; CGFloat imageWidth = imageHeight * image.size.width / image.size.height; imageView.frame = CGRectMake(floor((284 - imageWidth)/2), 47, imageWidth, imageHeight); [alert addSubview:imageView]; [alert show]; [alert release];