I try to make a Popup for my app with UIAlertView. This Popup display fine on iOS 10 or older but on iOS 11 it doesn't display all the content of the popup. What can I do to fix that error!?
And this is the code that I am using to make the custom UAlertView
. Any ideas?
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles: nil];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 900, 900)];
[lbl setAttributedText:getPopUp];
[lbl setNumberOfLines:0];
[lbl sizeToFit];
[lbl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg-popup-2.png"]]];
[alert setValue:lbl forKey:@"accessoryView"];
[alert show];
Sorry for my poor English! Regards! thanks for all your help!!
Use UIAlertController
instead of UIAlertView
.
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:title //alert Title
message:getPopUp //Your Message
preferredStyle:UIAlertControllerStyleAlert];
UIView *firstSubview = alert.view.subviews.firstObject;
UIView *alertContentView = firstSubview.subviews.firstObject;
for (UIView *subSubView in alertContentView.subviews) {
subSubView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg-popup-2.png"]];
}
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
Hope this will help you.
For more details: http://hayageek.com/uialertcontroller-example-ios/