iOS 11 UIAlertview未显示完整消息

时间:2018-05-17 09:32:20

标签: objective-c ios11 uialertview

我尝试使用UIAlertView为我的应用制作Popup。此弹出窗口在iOS 10或更早版本上显示正常,但在iOS 11上它不显示弹出窗口的所有内容。我该怎么做才能解决这个错误!? 这是我用来制作自定义UAlertView的代码。有什么想法吗?

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

抱歉我的英语不好! 问候!谢谢你的帮助!!

2 个答案:

答案 0 :(得分:2)

UIAlertView已被弃用。您应该使用UIAlertController,而不是使用UIAlertView: -

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

答案 1 :(得分:1)

使用UIAlertController代替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];

希望这会对你有所帮助。
有关详细信息:http://hayageek.com/uialertcontroller-example-ios/