iOS Question [Solved] CSBuilder - MaterialIcon - doesn'twork on b4xview button/Label

AymanA

Member
Licensed User
Hi All,

I am sorry if this is basic question as I am trying to grasp the transition from B4A to B4I, I am trying to assign MaterialIcon or fontawesome + text using CSBuilder.

Based on this link it should work with AttributedString, but can not find this when I am using b4xview (by button/label is b4xview as I am trying cross platform), so how can I achieve the below:

B4X:
cs.Font(Font.CreateMaterialIcons(20)).Color(0xFF777777).Append(Chr(0xE7FD)).Append("test").PopAll
    Main_Button1.Text =  cs
1603147110760.png


Thanks in advance for the assistance
 

Star-Dust

Expert
Licensed User
B4X:
MainButton1.AttributedText=Cs
see also
 

AymanA

Member
Licensed User
MainButton1.AttributedText=Cs
Thank you for your reply, I am using b4xview so seems this attribute doesn't exist for b4xview:

1603171730075.png


But following the link works perfectly fine for the b4xview when checking if it is a label - still same problem if I am checking if it is a button - so seems the attributedtext only works with labels!

Thank you so much for for your help and all your contributions on this forum, I am a follower to your awesome work :)
 

Star-Dust

Expert
Licensed User
Yes, you are right, it only works with a Label.

B4X:
Dim cs As CSBuilder
ButtonSetAttributedText(Button1, _
   cs.Initialize.Color(Colors.Red).Append("Click ").Font(Font.CreateNewBold(30)).Append("Me!!!").PopAll, _
   cs.Initialize.Color(Colors.Gray).Append("Click ").Font(Font.CreateNewBold(30)).Append("Me!!!").PopAll, _
   cs.Initialize.Append("disabled"))

Sub ButtonSetAttributedText(btn As Button, NormalText As AttributedString, HighlightedText As AttributedString, _
     DisabledText As AttributedString)
   Dim no As NativeObject = btn
   no.RunMethod("setAttributedTitle:forState:", Array(NormalText, 0))
   no.RunMethod("setAttributedTitle:forState:", Array(HighlightedText, 1))
   no.RunMethod("setAttributedTitle:forState:", Array(DisabledText, 2))
End Sub
see:
 

Star-Dust

Expert
Licensed User
I would add this.

B4X:
Public Sub SetTextOrCSBuilderToLabelOrButton(Label_or_Button As B4XView, Text As Object)
   #if B4A or B4J
   Label_or_Button.Text = Text
   #else if B4i
    If Text Is CSBuilder Then
        If Label_or_Button Is Label Then
            Dim lbl As Label = Label_or_Button
            lbl.AttributedText = Text
        else if Label_or_Button Is Button Then
            Dim no As NativeObject = Label_or_Button
            Dim AText As AttributedString = Text
            'normal text
            no.RunMethod("setAttributedTitle:forState:", Array(AText, 0))
            'Highlighted Text
            no.RunMethod("setAttributedTitle:forState:", Array(AText, 1))
            ' disabled text
            no.RunMethod("setAttributedTitle:forState:", Array(AText, 2))
        End If
    Else
        If GetType(Text) = "__NSCFNumber" Then Text = "" & Chr(Text)
        Label_or_Button.Text = Text
    End If
   #end if
End Sub
 
Last edited:
Top