How to add image with text into UIAlertView?

2019-06-26 09:14发布

问题:

I want to add image with some text into UIAlertView like given image below

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 image is not showing inside alertview. Your help will be appreciable. Thanks

回答1:

It is emoji. You can find the entire unicode of emoji's here: Emoji Unicode

You can use the unicode of corresponding image to show that in your alert like:

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


回答2:

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];

i hope this will help u

If you are use in IOS 7 , We can not add the Image in IOS 7 Because In IOS 7 Remove all addSubview Functionality....So can not add the Image in IOS7.