Search code examples
uiimageviewios8uialertviewaccessoryview

UIAlertView with UIImageView in accessoryView


I am giving an UIImageView in the UIAlertView's accessoryView by the following code:

   UIAlertView *alertView = [[UIAlertView alloc]init];

   [alertView addButtonWithTitle:@"Cancel"];
   [alertView addButtonWithTitle:@"OK"];
    UIImageView *someImageView = /*initialization code */;

   [someImageView setFrame:CGRectMake(0,0,40 ,20)];

   [alertView someImageView forKey:@"accessoryView"];
   [alertView show];

The above code works fine with iOS7 but since the update to iOS8 the alertView looks elongated and disoriented. I have tried changing the constraints and the aspect ratio of the image that is set in the UIImageView. Can someone help me with this?


Solution

  • This is not a supported use of UIAlertView:

    The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

    Additionally, UIAlertView is deprecated in iOS 8.

    You should build your own view to present, or use one of the many open-sourced options on GitHub/CocoaControls, like SDCAlertView or ios-custom-alertview.