How to add subview inside UIAlertView for iOS 7?
You can really change accessoryView to customContentView in iOS7 (and it seems that in iOS8 as well) UIAlertView
[alertView setValue:customContentView forKey:@"accessoryView"];
Try this code:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 40)];
[av setValue:v forKey:@"accessoryView"];
v.backgroundColor = [UIColor yellowColor];
[av show];
Remember that you need set custom accessoryView before the call [alertView show]
Add UILabel Inside UIAlertView in iOS7
AddSubview is not possible from iOS 7.
How to add subview inside UIAlertView for iOS 7?
iOS 7 UIDatePicker in UIAlertView customisation
This is my component to support addSubview in AlertView.
CXAlertView - Custom alert-view which allow you to add view as main content.
How to add multiple UITextFields to a UIAlertView in iOS 7?
You can't do this any more, there is no addSubview
for UIAlertView
any more in iOS7.
Below are good alternative:
ios-custom-alertview
MZFormSheetController
UIAlertView Buttons(subviews) is not Showing in iOS 7
We can add subviews to UIAlerView by adding subview to the presentedViewController's view when UIAlertView is presented. I have accessed UIAlertView like following way :
NSArray *subviews = [UIApplication sharedApplication].keyWindow.rootViewController.presentedViewController.view.subviews;
I have 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;
}
// You can Customise this based on your requirement by adding subviews.
- (void)didPresentAlertView:(UIAlertView *)alertView
{
NSArray *subviews = [UIApplication sharedApplication].keyWindow.rootViewController.presentedViewController.view.subviews;
if( subviews.count > 1 )
{
// iOS while presenting an alertview uses a presening view controller. That controller's view has several subviews. I have picked one
// subview from it which has frame similar to the alertview frame.
UIView *presentedView = [subviews objectAtIndex:1];
UIActivityIndicatorView *customActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[customActivityIndicator startAnimating];
customActivityIndicator.center = ACTIVITY_INDICATOR_CENTER;
[presentedView addSubview:customActivityIndicator];
}
}
@end
In - (void)didPresentAlertView:(UIAlertView *)alertView method I have added the subviews to UIAlertView by accessing Presented View Controller's view.
You can find explanation and code example for this on Here
Related Topics
Required Ipv6 Compatibility - iOS App Rejected by Apple
In iOS, How to Store a Secret "Key" That Will Allow Me to Communicate with My Server
How to Use Any in Codable Type
Xcode 9 Swift Language Version (Swift_Version)
Uigesturerecognizer and Uitableviewcell Issue
Customizing the More Menu on a Tab Bar
Combine Framework: How to Process Each Element of Array Asynchronously Before Proceeding
Cannot Change Search Bar Background Color
How to Find File Uti for File, Withouth Pathextension, in a Path in Swift
Swift Apply .Uppercasestring to Only the First Letter of a String
Wait Until Multiple Networking Requests Have All Executed - Including Their Completion Blocks
Adding a Uilabel to a Uitoolbar
Parsing Nested Array of Dictionaries Using Object Mapper
Uibutton Image Behavior Changed in iOS 15
How to Integrate Facebook Without Redirect Safari Browser in iOS App with Latest Fbsdk