【发布时间】:2012-02-13 06:13:08
【问题描述】:
我想在UIAlertView 的消息中添加一个可点击的网址链接。
这样当用户看到警报视图时,他们可以触摸消息内的链接。或者,他们可以通过单击“确定”按钮继续下一步。
有可能吗?如何?
【问题讨论】:
标签: objective-c url hyperlink message uialertview
我想在UIAlertView 的消息中添加一个可点击的网址链接。
这样当用户看到警报视图时,他们可以触摸消息内的链接。或者,他们可以通过单击“确定”按钮继续下一步。
有可能吗?如何?
【问题讨论】:
标签: objective-c url hyperlink message uialertview
我认为实现您尝试的唯一方法是通过自定义警报视图。
您可以采取多种方法。一个是子类化 UIAlertView,在这里你可以找到一个简短的教程:Subclass UIAlertView。然后,在您的子类中,您可以以任何您喜欢的方式构建警报来实现启用触摸的文本。看看this tutorial 的方法。
【讨论】:
我今天遇到了这个问题,我需要在我的警报视图中包含可点击的电话号码和地址,并且因为无法自定义警报视图而被难住了一段时间。
经过一些研究,您似乎可以将文本视图添加到警报视图中,这似乎解决了我的问题。这是我允许动态缩放警报视图的方法(注意:将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();
【讨论】: