Stupid UIAlertView Tricks: Part I

Earlier this evening I was answering a StackOverflow question about putting a UITextView onto a UIAlertView. I had done this before with UITextFields (I wrote a post about it), but I’d never tried it before with a UITextView. Well, it turns out to totally work.

However, it got me thinking about jamming random other views into a UIAlertView. The logical conclusion of which was this: StackOverflow in a UIAlertView.

StackOverflow in a UIAlertView

Why? I dunno. Cool though, right?

- (void) doAlertViewWithWebView
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"stackoverflow"
                   message:@"\n\n\n\n\n\n\n\n\n\n\n\n"
                  delegate:nil
         cancelButtonTitle:nil
         otherButtonTitles:@"OK", nil];

    UIWebView *myView = [[[UIWebView alloc] initWithFrame:CGRectMake(10, 40, 264, 254)] autorelease];
    myView.scalesPageToFit = YES;
    [alert addSubview:myView];

    [myView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]]];

    [alert show];
    [alert release];
}

If you want to follow me, I’m @zpasternack on Twitter and on app.net.