如何将可触摸的 Url 链接添加到 UIAlertView 消息中的 url?

发布于 2024-12-28 04:01:28 字数 122 浏览 1 评论 0原文

我想将一个可点击的网址链接添加到 UIAlertView 的消息中。 这样,当用户看到警报视图时,他们可以触摸消息内的链接。或者,他们可以单击“确定”按钮继续下一步。

有可能做到吗?如何?

I want to add a clickable link of an url into UIAlertView's message.
Such that when user sees the alert view, they can can touch on link inside message. Alternatively they can go next by clicking on the OK button.

Is possible to do it? How?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东风软 2025-01-04 04:01:28

我认为实现您想要的唯一方法是通过自定义警报视图。

您可以采取多种方法。一种是 UIAlertView 的子类化,在这里您可以找到一个简短的教程:子类 UIAlertView。然后,您可以在您的子类中以任何您喜欢的方式构建警报来实现支持触摸的文本。查看本教程一种方法来做到这一点。

The only way I see to implement what you are trying to is through a custom alert view.

There are several approaches that you can take. One is subclassing UIAlertView and here you can find a short tutorial: Subclass UIAlertView. In your subclass you could then build the alert any way you like to implement the touch-enabled text. Have a look at this tutorial for a way to do it.

风渺 2025-01-04 04:01:28

我今天遇到了这个问题,我需要在警报视图中包含可点击的电话号码和地址,并且由于自定义警报视图无法实现而被难住了很长一段时间。

经过一番研究后,您似乎可以将文本视图添加到警报视图中,这似乎解决了我的问题。这是我的方法,允许动态缩放警报视图(注意:将 C# 与 Xamarin 结合使用):

// create text view with variable size message
UITextView alertTextView = new UITextView();
alertTextView.Text = someLongStringWithUrlData;

// enable links data inside textview and customize textview
alertTextView.DataDetectorTypes = UIDataDetectorType.All;
alertTextView.ScrollEnabled = false; // is necessary 
alertTextView.BackgroundColor = UIColor.FromRGB(243, 243, 243); // close to alertview default color
alertTextView.Editable = false;

// create UIAlertView 
UIAlertView Alert = new UIAlertView("Quick Info", "", null, "Cancel", "OK");
Alert.SetValueForKey(alertTextView, (Foundation.NSString)"accessoryView");

// IMPORTANT/OPTIONAL need to set frame of textview after adding to subview
// this will size the text view appropriately so that all data is shown (also resizes alertview
alertTextView.Frame = new CoreGraphics.CGRect(owner.View.Center, alertTextView.ContentSize);
Alert.Show();

I ran into this problem today, I needed to have clickable phone numbers and addresses in my alert view and was stumped for quite awhile as custom alert views are out of the question.

After some research it seems that you can add a textview to an alertview which seemed to solve my problem. Here is my approach that allows for dynamically scaling alertviews (note: using C# with Xamarin):

// create text view with variable size message
UITextView alertTextView = new UITextView();
alertTextView.Text = someLongStringWithUrlData;

// enable links data inside textview and customize textview
alertTextView.DataDetectorTypes = UIDataDetectorType.All;
alertTextView.ScrollEnabled = false; // is necessary 
alertTextView.BackgroundColor = UIColor.FromRGB(243, 243, 243); // close to alertview default color
alertTextView.Editable = false;

// create UIAlertView 
UIAlertView Alert = new UIAlertView("Quick Info", "", null, "Cancel", "OK");
Alert.SetValueForKey(alertTextView, (Foundation.NSString)"accessoryView");

// IMPORTANT/OPTIONAL need to set frame of textview after adding to subview
// this will size the text view appropriately so that all data is shown (also resizes alertview
alertTextView.Frame = new CoreGraphics.CGRect(owner.View.Center, alertTextView.ContentSize);
Alert.Show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文