Thái Salem
Thái Salem

Reputation: 43

iOS 11 UIAlertview not show full Message

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];

Click here to see example

Sorry for my poor English! Regards! thanks for all your help!!

Upvotes: 4

Views: 804

Answers (2)

Faysal Ahmed
Faysal Ahmed

Reputation: 7669

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/

Upvotes: 2

Kuldeep Tanwar
Kuldeep Tanwar

Reputation: 3526

UIAlertView has been deprecated. Instead of using UIAlertView you should use UIAlertController like this :-

 UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
 UIAlertAction *actionOk=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //Ok Button Code
    }];
  UIAlertAction *actionCancel=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        //Cancel Button Code
    }];
  [alertController addAction:actionOk];
  [alertController addAction:actionCancel];

  [self presentViewController:alertController animated:YES completion:nil];

Upvotes: 2

Related Questions