iOS Question [SOLVED] CSBuilder clickable link color in B4i. How to change it?

JordiCP

Expert
Licensed User
Longtime User
I wanted to update an already existing B4i app and thought it wouldn't take me much ?...but here I am.

In this version, some explanatory texts are to be added to a TextView, and some parts of which should be clickable. So I thought of using CSBuilder. However, by design, the clickable parts must be a different color that the one iOS is showing (blue), and I can't get it to change whatever I try

Does anyone know the proper way to change the color of clickable links by using CSBuilder in B4i? I've tried with (just testing)
B4X:
Dim cs As CSBuilder
    cs.Initialize.Alignment("ALIGN_LEFT")
    cs.Append("example text1")
    cs.Link("link1").Color(Colors.White).Underline.Append("This is my Link").Pop.Pop.Pop
    cs.Append("example text2")
   cs..PopAll

and also tried with the B4A CSBuilder tutorial approach (a separate CSBuilder), but it is not compatible with B4i's CSBuilder.


I'm wondering if I am missing something obvious, or it works like this and I must take another approach
 
Solution
Ok. Seems that it doesn't matter which color is set in a CSBuilder's link, because it is overriden by a UITextView's property
Dived into the UITextView documentation and also found this stackOverflow post doing something similar.

In case someone else needs it in the future, it can be done like this
B4X:
#if OBJC
// Here fixed attributes are used. Could be expanded to be customizable
-(void) changeTextViewLinkAttributes:(UITextView*) textView  {

    NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor],
                                 NSUnderlineColorAttributeName: [UIColor lightGrayColor],
                                 NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}...

JordiCP

Expert
Licensed User
Longtime User
Ok. Seems that it doesn't matter which color is set in a CSBuilder's link, because it is overriden by a UITextView's property
Dived into the UITextView documentation and also found this stackOverflow post doing something similar.

In case someone else needs it in the future, it can be done like this
B4X:
#if OBJC
// Here fixed attributes are used. Could be expanded to be customizable
-(void) changeTextViewLinkAttributes:(UITextView*) textView  {

    NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor],
                                 NSUnderlineColorAttributeName: [UIColor lightGrayColor],
                                 NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
    textView.linkTextAttributes = linkAttributes;    
}
#End If

and I call it with
B4X:
' myTextView is a previously declared and initialized TextView
    Me.As(NativeObject).RunMethod("changeTextViewLinkAttributes:", Array(myTextView))
 
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…