I am having an application on iTunes store which displays some UILabel
and UIWebView
on UIAlertView
. According to session video, addSubView
for UIAlertView
will not work. They have talked about ContentView
. But in the GM Seeds SDK, I could not find that property and there seems to be no other way.
The only thing I can do is to create a custom subclass of UIView
and make it work like UIAertView
. Can you suggest any other simple solution?
Thanks for the help.
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]
AddSubview is not possible from iOS 7.
The only way is to create a custom UIView subclass which can act as UIAlertView. I could find out few components on Github.
The linked one Custom Alert seems to work well. By putting proper version check one can identify to go for native UIAlertView or CustomAlertView.
Adding a subview to an UIAlertView
is different in iOS7 from earlier iOS versions. Try something like this:
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[myAlertView setValue:myCustomView forKey:@"accessoryView"]; //works only in iOS7
} else {
myAlertView.message = @"\n"; //or just add \n to the end of the message (it's a workaround to create space inside the alert view
[myAlertView addSubview:myCustomView];
}
[myAlertView show]; //show the alert AFTER CUSTOMIZATION
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With