How to add image with text into UIAlertView?

本秂侑毒 提交于 2019-12-12 11:28:04

问题


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.

     



来源:https://stackoverflow.com/questions/16714053/how-to-add-image-with-text-into-uialertview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!