UITextViewLinkClickEvent
UITextViewLinkClickEvent represents the user tapping a link in multiline text, before the system opens it.
The linkclick event of UITextView is this class. It carries the link URL and its range in the text. When a listener calls preventDefault(), the system doesn't open the link, and the app handles it itself.
Inheritance: Event → UITextViewLinkClickEvent
Constructor
Creates a UITextViewLinkClickEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.
Instance properties
Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.
| Property | Description |
|---|---|
url read-only | The link URL |
range read-only | The range of the link in the text |
These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.
Events that use this class
| Object | Events |
|---|---|
UITextView | linkclick |
It can be canceled: cancelable is true, and calling preventDefault() keeps the system from opening the link.
Examples
const terms = new UITextView();
terms.isEditable = false;
terms.attributedText = new NSAttributedString('阅读《用户协议》', { link: 'https://example.com/terms' });
terms.addEventListener('linkclick', (e) => {
console.log(e instanceof UITextViewLinkClickEvent, e.url);
e.preventDefault();
});Effect: tapping 《用户协议》 prints true https://example.com/terms, and the system doesn't open the URL.
Corresponding iOS API
| ObjC | JS |
|---|---|
textView:primaryActionForTextItem:defaultAction: | The linkclick event |
textItem.link | event.url |
textItem.range | event.range |
Returning nil | Calling event.preventDefault() |
See also
linkclick: when it is firedUITextView