gpt4 book ai didi

ios - 如何在 iOS 中使 UIAlertView 变大?

转载 作者:可可西里 更新时间:2023-11-01 03:42:59 30 4
gpt4 key购买 nike

我在我的 iOS 应用程序中显示免责声明 UIAlertView,但 iOS 中的默认 AlertView 大小非常小。我怎样才能让它变大?

看起来应该很简单,但是我查了资料好像没有办法实现?

代码,

UIAlertView* alert = [[UIAlertView alloc] initWithTitle: @"Disclaimer" message: nil delegate: self cancelButtonTitle: @"Accept" otherButtonTitles: nil];

UIWebView* webView = [[UIWebView alloc] init];
[webView setFrame:CGRectMake(0, 0, 280, 140)];
[webView loadHTMLString: html baseURL: nil];
UIView* view = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 280, 140)];
[view addSubview: webView];
[alert setValue: view forKey: @"accessoryView"];
[alert show];

最佳答案

首先,使用您的 WebView 创建一个 View Controller ,我们称它为 MyWebViewController

然后您可以将其显示为全屏 Controller :

MyWebViewController* alertController = [[MyWebViewController alloc] init];
alertController.view.backgroundColor = [UIColor.lightGrayColor colorWithAlphaComponent:0.2];
alertController.modalPresentationStyle = UIModalPresentationOverFullScreen;

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

虽然这是一个全屏 Controller 。您必须在您的内容中心创建一个 View ,为该 View 添加边框并使所有内容保持半透明。

您还可以使用弹出框:

UIView *sourceView = self.view;

MyWebViewController* alertController = [[MyWebViewController alloc] init];
alertController.modalPresentationStyle = UIModalPresentationPopover;

alertController.preferredContentSize = CGRectInset(self.view.bounds, 20, 100).size;
alertController.popoverPresentationController.canOverlapSourceViewRect = YES;
alertController.popoverPresentationController.sourceView = sourceView;
alertController.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(sourceView.bounds), CGRectGetMidY(sourceView.bounds), 0, 0);
alertController.popoverPresentationController.permittedArrowDirections = 0;
alertController.popoverPresentationController.delegate = self;

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

委托(delegate)人还必须实现:

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
return UIModalPresentationNone;
}

源 View 通常是打开弹出窗口的按钮,但我使用父 View 来确保弹出窗口居中。

您还必须添加由 UIAlertView 自动添加的按钮,但这应该是微不足道的。

关于ios - 如何在 iOS 中使 UIAlertView 变大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43659662/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com