Cant click on button in UIAlertView after adding UIImageview to subView

434 Views Asked by At

The Ok button is not working. I know it happened because I added backgroundImageView. How can i make it work?

This is my code:

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"clock"]];

backgroundImageView.frame = CGRectMake(0, 0, 282, 200);

backgroundImageView.contentMode = UIViewContentModeScaleToFill;
backgroundImageView.userInteractionEnabled = YES;

[alert addSubview:backgroundImageView];

[alert sendSubviewToBack:backgroundImageView];

[alert show];
4

There are 4 best solutions below

4
On

Don't add subviews to UIAlertView, it is not supported functionality. If you need to create custom views, find a 3rd parts alert view solution which supports what you need and use that instead.

0
On

Apple does not recommend adding subviews to UIAlertView You will have to create your own alert view.

0
On

Unfortunately Apple will not allow you to add subviews or modify the view hierarchy. See https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html for:

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.

And see https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UIAlertView.html#//apple_ref/doc/uid/TP40012857-UIAlertView for:

Appearance of Alert Views

You cannot customize the appearance of alert views.

Going against these will get your App rejected in the Apple Review process - so I would go back and look at your design of your app.

0
On

Apple will not allow you to add subviews to UIAlertView. Subclassing UIAlertView is not an option, this class is not intended to be subclassed and doing so might be a reason of app rejection.

You can use a library from here for custom UIAlertView