views:

652

answers:

2

Is it possible to add image in the AlertView?like showing image from plist file.

Need help. Thanks

+1  A: 

You'll need to subclass UIAlertView and rearrange its subviews a bit. There are several tutorials for this kind of stuff:

Rob Napier
But I think rearranging the subviews may lead to rejection of the app.
Madhup
+2  A: 

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];
    [bkgImg release];
    [path release];

    [successAlert addSubview:imageView];
    [imageView release];

    [successAlert show];
    [successAlert release];

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

Hope this helps.

Thanks,

Madhup

Madhup
works perfectly..thanks! but if i shift the image to the centre it will be blocked by the message..how can i do it in such a way that the image is in the centre then below the image would be the message?
summer
The only thing regarding this you can do is add another label for the message and append \n\n\n... in the end of your title This is the only way I know which does not uses the non-documented features.
Madhup