Is it possible to show an Image in UIAlertView?

后端 未结 9 455
别跟我提以往
别跟我提以往 2020-11-29 02:01

Is it possible to add image in an UIAlertView, like showing an image from the plist file?

9条回答
  •  自闭症患者
    2020-11-29 02:26

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

提交回复
热议问题