Following up my previous post I wonder if it is possible to make text selectable and copy it to clipboard, for a MobileLabel on iOS?
ChatGPT is suggesting declares …
In Xojo iOS development, MobileLabel does not support selectable text by default. It is a simple label control that displays non-interactive text.
Workaround for Selectable Text in iOS Custom Cells
To make text selectable inside a MobileTableCustomCell, you need to use a UITextView or UILabel configured from a custom iOSCustomControl. Xojo allows wrapping native UIKit controls using iOSCustomControl.
Steps to Make Selectable Text in a Custom Cell:
- Create an iOSCustomControl subclass.
- In the Open event of the control, instantiate a native UITextView or UILabel using a Declare.
- Enable user interaction and selection.
- Add it as a subview to the control’s native handle.
- Use this custom control in your MobileTableCustomCell instead of MobileLabel.
Sample Code Using
UITextView
in
iOSCustomControl
:
#If TargetiOS Then Declare Function Create UITextView Lib "UIKit" Selector "initWithFrame:" (cls As Ptr, frame As CGRect) As Ptr Declare Sub AddSubview Lib "UIKit" Selector "addSubview:" (parent As Ptr, child As Ptr) Declare Sub SetSelectable Lib "UIKit" Selector "setSelectable:" (tv As Ptr, flag As Boolean) Declare Sub SetEditable Lib "UIKit" Selector "setEditable:" (tv As Ptr, flag As Boolean) Declare Sub SetText Lib "UIKit" Selector "setText:" (tv As Ptr, text As CFStringRef) Declare Function UIColor_whiteColor Lib "UIKit" Selector "whiteColor" (cls As Ptr) As Ptr Declare Sub SetBackgroundColor Lib "UIKit" Selector "setBackgroundColor:" (tv As Ptr, color As Ptr) Dim frame As New CGRect(0, 0, Me.Width, Me.Height) Dim tvPtr As Ptr = CreateUITextView(NSClassFromString("UITextView"), frame) SetEditable(tvPtr, False) SetSelectable(tvPtr, True) SetText(tvPtr, "Your selectable text here") SetBackgroundColor(tvPtr, UIColor_whiteColor(NSClassFromString("UIColor"))) AddSubview(Self.Handle, tvPtr) #EndIf