How to add UIImageView in UIAlertController?

前端 未结 3 801
情深已故
情深已故 2020-12-31 19:45

I want UIAlertController to present an alert with UIImageView in an ActionSheet. But when I run the application it is terminating.

3条回答
  •  醉梦人生
    2020-12-31 20:22

    It is not possible to add an image to a UIAlertController according to Apple Doc.

    if you want then you can create your own custom view like:

    https://github.com/wimagguc/ios-custom-alertview

    If you want to take image appear on button then Try like this:

    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Title"
                                  message:@"Welcome"
                                  preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction* okButton = [UIAlertAction actionWithTitle:@"OK"
                                style:UIAlertActionStyleCancel
                                handler:^(UIAlertAction * action) {
                                  //Do some thing here
                                }];
    
    [okButton setValue:[[UIImage imageNamed:@"kaga.jpg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
    
    [alert addAction:okButton];
    [self presentViewController:alert animated:YES completion:nil];
    

提交回复
热议问题