iOS Question Set NO_GRAVITY for label or textview

Pooya1

Active Member
Licensed User
Sorry
The relevant url didn't help me
My text is :

I try to use below code but not working
Again sorry
B4X:
Dim cs As CSBuilder
    cs.Initialize
    Dim no As NativeObject = cs
    Dim paragraph As NativeObject
    paragraph = paragraph.Initialize("NSMutableParagraphStyle").RunMethod("new", Null)
    paragraph.SetField("baseWritingDirection", 1) 'NSWritingDirectionRightToLeft
    no.RunMethod("addAttribute:value:range:", Array("NSParagraphStyle", paragraph, no.MakeRange(0, cs.Length)))
    cs.Append(Label1.Text)
    Label1.AttributedText    =    cs.PopAll
 
Upvote 0

Pooya1

Active Member
Licensed User
Finally i decided use CSBuilder for detect word and set alignment for it
In below code
Function detect all English word and set Left alignment for it and if word not is English so set Right alignment for it
Also in this function,all link exist in string convert to real link that user can click on it

B4X:
Sub MarkPatternCSbuilder(Textview2 As TextView,CS As CSBuilder,Input As String, Pattern As String, GroupNumber As Int) As CSBuilder
    
    Pattern    =    "((([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,])+)|(http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,\s]*)?))"
    
    Dim lastMatchEnd As Int = 0
    Dim m As Matcher = Regex.Matcher(Pattern, Input)
    
    Do While m.Find
        
        Dim currentStart As Int = m.GetStart(GroupNumber)
        Dim temp As String
        temp    =    Input.SubString2(lastMatchEnd, currentStart)
        CS.Append(temp)
        lastMatchEnd = m.GetEnd(GroupNumber)

        Dim temp As String
        temp    =    m.Group(GroupNumber)
        
        If Regex.IsMatch("(http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?)",temp) Then
            CS.Color(Colors.RGB(91,35,179))
            CS.Alignment("ALIGN_LEFT")
            CS.Link(temp)
            CS.Append(temp)
            CS.Pop.Pop
        
        Else If Regex.IsMatch("([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,\s])+",temp) Then
            CS.Color(Textview2.TextColor)
            CS.Font(Textview2.Font)
            CS.Alignment("ALIGN_LEFT")
            CS.Append(temp)
            CS.Pop.Pop
            
        Else
            CS.Color(Textview2.TextColor)
            CS.Font(Textview2.Font)
            CS.Alignment("ALIGN_RIGHT")
            CS.Append(temp)
            CS.Pop.Pop
            
        End If
    Loop
    
    If lastMatchEnd < Input.Length Then
        CS.Font(Textview2.Font)
        CS.Append(Input.SubString(lastMatchEnd)).Pop
    End If
    
    Return CS
    
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…