iOS Question CSBuilder attributed string

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

I'm trying to show fontawesome icons on labels and doesn't work. Instead of icons I see only a ?
All icons are taken from here https://fontawesome.com/start

Please see my code - what am I dong wrong?

B4X:
Private Sub Show3
    Try
        Dim csMAR1,csVitals1,csSeizure1,csRecording1 As CSBuilder
        Dim Size As Int=30
        
        lblVitals.Multiline=True
        lblSeizureLog.Multiline=True
        lblMAR.Multiline=True
        lblRecording.Multiline=True
        
        lblMAR.Color=Colors.Blue
        lblVitals.Color=Colors.Blue
        lblSeizureLog.Color=Colors.Blue
        lblRecording.Color=Colors.Blue
        
        csMAR1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)       
        csMAR1.Append(CRLF).Font(Font.CreateNewBold(Size)).Color(Colors.white).Append(Chr(0xff5b1)).Append(CRLF).Append("MAR").Pop.Pop
        csMAR1.PopAll
        lblMAR.AttributedText=csMAR1 ' doesn't work
        
        csVitals1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csVitals1.Append(CRLF).Font(Font.CreateNewBold(Size)).Color(Colors.white).Append(Chr(0xf004)).Append(CRLF).Append("Vitals").Pop.Pop
        csVitals1.PopAll
        lblVitals.AttributedText=csVitals1 ' works
        
        csSeizure1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csSeizure1.Append(CRLF).Font(Font.CreateNewBold(Size)).Color(Colors.white).Append(Chr(0xf5dc)).Append(CRLF).Append("Seizure").Pop.Pop
        csSeizure1.PopAll
        lblSeizureLog.AttributedText=csSeizure1 ' doesn't work
        
        csRecording1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csRecording1.Append(CRLF).Font(Font.CreateNewBold(Size)).Color(Colors.white).Append(Chr(0xf3c9)).Append(CRLF).Append("Recording").Pop.Pop
        csRecording1.PopAll
        lblRecording.AttributedText=csRecording1 ' doesn't work
        
        
        
        
        
    Catch
        Log(LastException)
    End Try
End Sub

I also attached my project.

All I need is to show 4 icons for brain, microphone, heart and RX.

Thank you.
 

Attachments

  • Eye.zip
    178.7 KB · Views: 29

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
shouldn't you be using Font.CreateFontAwesome for the character?

B4X:
 csSeizure1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csSeizure1.Append(CRLF).Color(Colors.white).font(font.createfontawesome(size)).Append(Chr(0xf5dc)).pop.Append(CRLF).Font(Font.CreateNewBold(Size)).Append("Seizure").Pop.Pop
        csSeizure1.PopAll
        lblSeizureLog.AttributedText=csSeizure1 ' doesn't work
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
shouldn't you be using Font.CreateFontAwesome for the character?

B4X:
 csSeizure1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csSeizure1.Append(CRLF).Color(Colors.white).font(font.createfontawesome(size)).Append(Chr(0xf5dc)).pop.Append(CRLF).Font(Font.CreateNewBold(Size)).Append("Seizure").Pop.Pop
        csSeizure1.PopAll
        lblSeizureLog.AttributedText=csSeizure1 ' doesn't work
that's what I am doing
B4X:
font(font.createfontawesome(size)).Append(Chr(0xf5dc))

exactly like in Erel's example https://www.b4x.com/android/forum/threads/csbuilder-attributedstrings-builder.79153/
B4X:
cs.Append("Apple: ").Font(Font.CreateFontAwesome(20)).Color(0xFF777777).Append(Chr(0xF179)).Pop.Pop.Append(CRLF)
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
I don't see any CreateFontAwesome call in your code.
Yes, my fault.
I changed it but it still doesn't work

B4X:
Private Sub Show3
    Try
        Dim csMAR1,csVitals1,csSeizure1,csRecording1 As CSBuilder
        Dim Size As Int=30
        
        lblVitals.Multiline=True
        lblSeizureLog.Multiline=True
        lblMAR.Multiline=True
        lblRecording.Multiline=True
        
        lblMAR.Color=Colors.Blue
        lblVitals.Color=Colors.Blue
        lblSeizureLog.Color=Colors.Blue
        lblRecording.Color=Colors.Blue
        
        csMAR1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)       
        csMAR1.Append(CRLF).Font(Font.CreateFontAwesome(Size)).Color(Colors.white).Append(Chr(0xff5b1)).Append(CRLF).Append("MAR").Pop.Pop
        csMAR1.PopAll
        lblMAR.AttributedText=csMAR1 ' doesn't work
        
        csVitals1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csVitals1.Append(CRLF).Font(Font.CreateFontAwesome(Size)).Color(Colors.white).Append(Chr(0xf004)).Append(CRLF).Append("Vitals").Pop.Pop
        csVitals1.PopAll
        lblVitals.AttributedText=csVitals1 ' works
        
        csSeizure1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csSeizure1.Append(CRLF).Font(Font.CreateFontAwesome(Size)).Color(Colors.white).Append(Chr(0xf5dc)).Append(CRLF).Append("Seizure").Pop.Pop
        csSeizure1.PopAll
        lblSeizureLog.AttributedText=csSeizure1 ' doesn't work
        
        csRecording1.Initialize.Alignment("ALIGN_CENTER").VerticalAlign(0)
        csRecording1.Append(CRLF).Font(Font.CreateFontAwesome(Size)).Color(Colors.white).Append(Chr(0xf3c9)).Append(CRLF).Append("Recording").Pop.Pop
        csRecording1.PopAll
        lblRecording.AttributedText=csRecording1 ' doesn't work
        
    Catch
        Log(LastException)
    End Try
End Sub
 

Attachments

  • iOS.jpg
    iOS.jpg
    25.6 KB · Views: 29
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Are you sure your FOntAwsome codes are correct? where did you get them from? Did you use the Icon Picker?

Also - 0xff5b1 - looks wrong. I would have expected 4 characters.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Are you sure your FOntAwsome codes are correct? where did you get them from? Did you use the Icon Picker?

Also - 0xff5b1 - looks wrong. I would have expected 4 characters.
I took them from this website https://fontawesome.com

for example -the RX icon https://fontawesome.com/icons/prescription?f=classic&s=solid. It shows the code f5b1. That's where it came from.

Now let's check the icons from Erel's example in his example we have the icon F179 - the URL for this icon is here https://fontawesome.com/icons/apple?f=brands&s=solid

The same goes for the another icon F17B https://fontawesome.com/icons/android?f=brands&s=solid

B4X:
Dim cs As CSBuilder
cs.Initialize.Alignment("ALIGN_CENTER")
cs.Append("Apple: ").Font(Font.CreateFontAwesome(20)).Color(0xFF777777).Append(Chr(0xF179)).Pop.Pop.Append(CRLF)
cs.Append("Android: ").Font(Font.CreateFontAwesome(20)).Color(0xFF057916).Append(Chr(0xF17B)).Pop.Pop
cs.PopAll
Label1.AttributedText = cs
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I think you can only use font awesome icons from the Icon Picker.

Some of these overlap with the wider font awesome characters.
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Desarrolle esta función que me ayuda para montar mis mensajes CSBUILDER.
Creo que está también por ahí, pero por si sirve de ayuda...

para probarla hacer algo como esto por ejemplo:
dim txt as string = "HOLA, #COLOR.RED#AMIGOS DEL #COLOR.YELLOW##FONTSIZE.25# MUNDO MUNDIAL"
dim csvar as csbuilder = GetCsBuilderTextULTIMAVERSION(txt)
msgbox csvar

En mis consultas sql, monto ese string, y así puedo perosnalizar todo desde el servidor:
SELECT
'#COLOR.CYAN#Vehículo: #COLOR.WHITE#' + COALESCE(Cod_Vehiculo,'') + dbo.crlf()+
'#COLOR.CYAN#Kilómetros: #COLOR.WHITE#' + isnull(ltrim(KilometrosActual), 'Sin revisón') +dbo.crlf()+
'#COLOR.CYAN#Fecha: ' + isnull(fecha,'') +
CASE WHEN Revision = 'OK' THEN ' #FONTSIZE.24##TYPEFACE.FONTAWESOME.0xF00C#' ELSE '-> #COLOR.RED##TYPEFACE.MATERIALICONS.0xE000##TYPEFACE.DEFAULT# ' + Revision END as TXTParaCLV,
Cod_Vehiculo + char(9) + ltrim(KilometrosActual) + char(9) + Revision + char(9) + Fecha as TxtParaclickEnClV
FROM



B4X:
public  Sub GetCsBuilderTextULTIMAVERSION(Texto As String ) As CSBuilder
    'ESTE ES EL BUENO
    Dim CS As CSBuilder
    Dim S As String
    'https://www.b4x.com/android/forum/threads/how-create-csbuilder-from-text-sequence.141657/#post-897915
   
    Try
        'FIRST SPLIT MUST BE A TEXT .   ********************************************** DELETE FIRST CHAR DOWN   #ESPECIAL CODE 1#
        Texto = " " & Texto
        Dim M() As String
       
        M = Regex.Split("#",Texto)
        'SAMPLE:
        'HOLA, #COLOR.RED#AMIGOS DEL #COLOR.YELLOW##FONTSIZE.25# MUNDO MUNDIAL
       
       
        CS.Initialize

        For f = 0 To M.Length-1
            s = M(f)
            If F = 0 Then   '**********************************************************DELETE DE FIRST CHAR ADD   #ESPECIAL CODE 1#
                S = S.SubString(1)
            End If
            If f Mod 2 = 1 Then
           
                Log(S.ToUpperCase)
           
                Select Case S.ToUpperCase
                    Case  "COLOR.RED"
                        CS.Color(Colors.Red)
                    Case  "COLOR.YELLOW"
                        CS.Color(Colors.Yellow)
                    Case  "COLOR.GREEN"
                        CS.Color(Colors.Green )
                    Case  "COLOR.MAGENTA"
                        CS.Color(Colors.Magenta )
                    Case  "COLOR.BLACK"
                        CS.Color(Colors.Black)
                    Case  "COLOR.WHITE"
                        CS.Color(Colors.White )
                    Case  "COLOR.CYAN"
                        CS.Color(Colors.Cyan )
                    Case  "COLOR.DARKGRAY"
                        CS.Color(Colors.DarkGray)
                    Case  "COLOR.GRAY"
                        CS.Color(Colors.Gray)
                    Case  "COLOR.LIGHTGRAY"
                        CS.Color(Colors.LightGray)
                    Case  "COLOR.TRANSPARENT"
                        CS.Color(Colors.Transparent)
                    Case "COLOR.BLUE"
                        CS.Color(Colors.Blue )
           
                   
                        '... MORE COLOR
               
                        'FUTURE IMPLEMETATIONS:**********************************************
                    Case Else
                       
                        If S.StartsWith("TYPEFACE.") Or S.StartsWith("FONTSIZE.") Then
                            'Log(S)
                            Dim UltimoPunto As Int
                            Dim ValorTrasUltimoPunto0X As String
                            UltimoPunto = S.LastIndexOf(".")
                            Dim ValorTrasUltimoPunto As String
                            Dim ValorPrevioUltimoPunto As String
                            ValorTrasUltimoPunto = S.SubString(UltimoPunto+1)
                            ValorPrevioUltimoPunto = S.SubString2(0,UltimoPunto)
                           
                           
                            'Chr(0xF2DC) ' nieve copo
                            Dim ii As Char
'                            Chr(0xF0E7)
                           
                            Dim ValorInt As Int
                            'SOLO PARA FONTAWESOME Y MATERIALICONOS
                            If  S.StartsWith("TYPEFACE.FONTAWESOME") Or S.StartsWith("TYPEFACE.MATERIALICONS") Then
                                If ValorTrasUltimoPunto.Length > 2 Then
                                    ValorTrasUltimoPunto0X = ValorTrasUltimoPunto.SubString(2)
                                    ValorInt = Bit.ParseInt(ValorTrasUltimoPunto0X,16)
                                    ii  = Chr(  ValorInt )
                                End If
                            Else
                                If ValorPrevioUltimoPunto = "TYPEFACE" Then   'TYPEFECE.LOQUESEA   (Y SIN MAS VALORES)
                                    ValorPrevioUltimoPunto = S
                                End If
                                ValorTrasUltimoPunto0X = ""
                                ValorInt= 0
                            End If
                           
                           
                            Select Case ValorPrevioUltimoPunto
                                Case "TYPEFACE.FONTAWESOME"
                                    CS.Typeface(Typeface.FONTAWESOME)
                                    CS.Append(ii)
                                Case  "TYPEFACE.MATERIALICONS"
                                    CS.Typeface(Typeface.FONTAWESOME)
                                    CS.Append(ii)
                                Case "TYPEFACE.DEFAULT"
                                    CS.Typeface(Typeface.DEFAULT)
                                    'SINO.. NO FUNCIONA
                                    CS.PopAll
                                Case "TYPEFACE.DEFAULTBOLD"
                                    CS.Typeface(Typeface.DEFAULT_BOLD)
                                Case "TYPEFACE.STYLE_ITALIC"
                                    CS.Typeface( Typeface.CreateNew(Typeface.DEFAULT, Typeface.STYLE_ITALIC))
                                Case "TYPEFACE.SERIF"
                                    CS.Typeface(Typeface.SERIF)
                                Case "FONTSIZE"
                                    ValorInt = Bit.ParseInt(ValorTrasUltimoPunto,10) 'BASE 10
                                    CS.Size(ValorInt)
                            End Select
                           
                        End If
                   
               
                       
                End Select
            Else
                CS.Append(S)
            End If




        Next
        CS.PopAll
   
        Return CS

    Catch
        Log(LastException)
        Return CS.Initialize.Append("Error: " & S).PopAll
    End Try


End Sub
 
Upvote 0
Top