We can add subviews to a UIAlerView by adding a subview to the presented ViewController when the UIAlertView is presented. I accessed the UIAlertView as follows:
NSArray * subviews = [UIApplication sharedApplication] .keyWindow.rootViewController.presentedViewController.view.subviews;
I created a subclass of UIAlerView:
Header file:
@interface MLKLoadingAlertView : UIAlertView - (id)initWithTitle:(NSString *)title; @end
Implementation File:
#import "MLKLoadingAlertView.h" #define ACTIVITY_INDICATOR_CENTER CGPointMake(130, 90) @implementation MLKLoadingAlertView - (id)initWithTitle:(NSString *)title { if ( self = [super init] ) { self.title = title; self.message = @"\n\n"; [self setDelegate:self]; } return self; }
In - (void) didPresentAlertView: (UIAlertView *) alertView method I added subviews to the UIAlertView, referring to the Viewed View Controller.
You can find an explanation and sample code for this on Here
source share