0

I want to have an UIAlertView with an image at top and some text under the image.

I know that UIAlertView is deprecated but I support the iOS version 7 and UIAlertController is not available in this version.

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[imageView setImage:[UIImage imageNamed:@"icon.png"]];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
NSString *about = [[NSString alloc] initWithFormat:@"%@\n\n\n\n%@\n%@\n(c) %@ Firm name", imageView, [[self bs] getAppName], [[self bs] getAppYear], [[self bs] getAppVersion]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:about delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert setValue:imageView forKey:@"accessoryView"];
[alert show];

How did I get the image at the top and the text above? Or can someone give me some good advice how I can solve my problem with a better method?

EDIT: I also saw this page (Is it possible to show an Image in UIAlertView?) bit it didn't helped me. I get the icon only at the end of my text.

Community
  • 1
  • 1
Premox
  • 323
  • 10
  • 25
  • possible duplicated to http://stackoverflow.com/questions/2323557/is-it-possible-to-show-an-image-in-uialertview – Twitter khuong291 Jan 11 '16 at 11:55
  • I noticed this topic, but it didn't solved my problem. The image is not displayed at the top. – Premox Jan 11 '16 at 11:59
  • use this Custom alert view source code https://github.com/wimagguc/ios-custom-alertview – iOS Developer Jan 11 '16 at 12:03
  • @iOS Developer How can I add some text under my image? I don't get it to add it under the image – Premox Jan 11 '16 at 12:33
  • 1
    You shouldn't "customize" UIAlertView anymore: "The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified." – Larme Jan 11 '16 at 14:37

1 Answers1

1

A couple of points:

  1. UIAlertView was deprecated in iOS 8. you're supposed to use UIAlertController instead.
  2. For both of those, you aren't supposed to mess with the view hierarchy. (I've added views to an alert view in the past, and then Apple changed something and it broke. Bad mojo.)

I suggest using a custom view controller made to look like an alert view. Check out this one on Github as an example:

Custom AlertView on Github

(I haven't used it; I just found it in the thread you posted.)

Duncan C
  • 128,072
  • 22
  • 173
  • 272