I need to be able to show a clickable url inline within a text area or label.
I don’t see an obvious way to do this, and I want to avoid having to roll a custom canvas for this.
I thought about using a HTML viewer, but id need many of these and I’m worried about memory footprint.
A canvas for a clickable url is relatively simple. There is a blog entry at the Xojo blog with really bad code for clickable links in a Text Area for desktop.
Can’t find the example code right now, but I use this:
Public Function ShowURL(url As String) As Boolean
// NSString* launchUrl = @"https://www.xojo.com/";
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
Declare Function NSClassFromString Lib "Foundation" (name As CFStringRef) As Ptr
Declare Function sharedApplication Lib "UIKit" Selector "sharedApplication" (obj As Ptr) As Ptr
Var sharedApp As Ptr = sharedApplication(NSClassFromString("UIApplication"))
// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/#//apple_ref/occ/clm/NSURL/URLWithString:
Declare Function URLWithString Lib "Foundation" Selector "URLWithString:" ( id As Ptr, URLString As CFStringRef ) As Ptr
Var nsURL As Ptr = URLWithString(NSClassFromString("NSURL"), url)
// https://developer.apple.com/documentation/uikit/uiapplication/1648685-openurl?language=objc
Declare Function openURL Lib "UIKit" Selector "openURL:options:completionHandler:" (id As Ptr, nsurl As Ptr, options As Ptr, handler As Ptr) As Boolean
Var b As New iOSBlock(AddressOf URLResult)
Return openURL(sharedApp, nsURL, Nil, b.Handle)
End Function
If you are displaying a very large text with multiple tappable links, using an HTML viewer is the best solution. But you will still need to implement the delegate known as WKNavigationDelegate.
If it is only a few links here and there I might have a solution (using MobileLabel and iOSKit), but need to test something first, I’ll keep you posted.