Is it possible to add image in an UIAlertView, like showing an image from the plist file?
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.
in iOS 7 or higher, use this code
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 282)];
UIImage *wonImage = [UIImage imageNamed:@"iberrys.png"];
imageView.contentMode=UIViewContentModeCenter;
[imageView setImage:wonImage];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Arirang List"
message:@"phiên bản: 1.0\n website: www.iberrys.com\n email: [email protected]\nmobile: 0918 956 456"
delegate:self
cancelButtonTitle:@"Đồng ý"
otherButtonTitles: nil];
//check if os version is 7 or above
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alertView setValue:imageView forKey:@"accessoryView"];
}else{
[alertView addSubview:imageView];
}
[alertView show];
You'll need to subclass UIAlertView and rearrange its subviews a bit. There are several tutorials for this kind of stuff:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With