Search code examples
objective-ciphoneuialertview

Is it possible to show an Image in UIAlertView?


Is it possible to add image in an UIAlertView, like showing an image from the plist file?


Solution

  • You can do it like:

    UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
    
        NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"smile.png"]];
        UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
        [imageView setImage:bkgImg];
    
        [successAlert addSubview:imageView];
    
        [successAlert show];
    

    This will add a image in the right corner of your alertview you can change the frame image to move around.

    Hope this helps.