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?
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:
- Custom UIAlertView (probably the most applicable to your problem)
- Custom UIAlertView w/ TableView (also very handy)
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"your Title" message:@"Your Message" delegate:nil cancelButtonTitle:@"Your Title" otherButtonTitles:nil];
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 40, 40)];
NSString *loc = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Your Image Name"]];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:loc];
[image setImage:img];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[Alert setValue:image forKey:@"accessoryView"];
}else{
[Alert addSubview:image];
}
[Alert show];
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];