How to add image with text to UIAlertView?

I want to add an image with some text in a UIAlertView as shown in the image below enter image description here

Here is my code

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please use Settings( ) to configure the phone number and image." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(160.5, 27, 15, 15)]; imageView.image = [UIImage imageNamed:@"settingIcon.png"]; [alert addSubview:imageView]; [alert show]; 

But the image is not displayed inside the alertview. Your help will be noticeable. Thanks

+4
source share
2 answers

This is emoji. Here you can find all unicode emoji: Unoode in Undoode format

You can use the unicode of the corresponding image to show what's in your alert, for example:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Midhun" message:@"\xE2\x9C\x88" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil]; [alert show]; 
+9
source

try this in iOS 6

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please use Settings(   ) to configure the phone number and image." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];       UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(160.5, 27, 15, 15)];       NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"settingIcon.png"]];    UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];    [imageView setImage:bkgImg];    [alert addSubview:imageView];    [alert show]; 

Hope this helps u

If you use in iOS 7, we cannot add an image in iOS 7, because in iOS 7, remove all the functionality of addSubview .... Therefore, you cannot add an image in iOS7.

+2
source

Source: https://habr.com/ru/post/1482384/


All Articles