简体   繁体   中英

UITextViewL link on xamarin.ios

I have a custom UITextView and need something like this:

<a href="www.google.es">Google</a>

By the way, This is my Initialize code on custom class:

void Initialize()
{
    Font = UIFont.FromName("Lacuna Regular", 14f);
    Editable = false;
    DataDetectorTypes = UIDataDetectorType.Link;
    Text = "Google";
}

but I don't know how to write the Url where I need to go (in this case, www.google.es).

Thanks in advance!

Via UIDataDetectorType.Links :

uiview.DataDetectorTypes = UIDataDetectorType.Link;
uiview.Text = @"https://www.google.es";

在此处输入图片说明

Via NSAttributedStringDocumentAttributes with NSAttributedString :

var urlString = @"<a href=""https://www.google.es"">Google</a>";
var documentAttributes = new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML };
NSError error = null;
var attributedString = new NSAttributedString(NSData.FromString(urlString, NSStringEncoding.UTF8), documentAttributes, ref error);
// Should really check the NSError before applying
uiview.AttributedText = attributedString;

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM