iOS Code Snippet AttributedStringPlus

Sometimes, meanwhile i work with AttributedString, i need to start more Span for a single Text, or i need to load a string from database o file (for example for translate). So i want to share this simple class, that for sure can be extended with other method. This helps to start a span for each words between marker, like RichString.

Is very easy to use

B4X:
    Dim l As Label
    l.Initialize("")
    Dim st As String = "Very short {b} Text {b} but i {b} want {b} to use Span!"
    Dim at As AttributedStringPlus
    at.Initialize( st.Replace("{b}","<b>"),Font.CreateNew(13),0xff424242)
    l.AttributedText = at.FormatFont(Font.CreateNewBold(14),"<b>")

Class uses Regex, so we can't use "{" "}" as marker
 

Attachments

  • AttributedStringPlus.bas
    1.7 KB · Views: 426
Last edited:
Top