iOS Question Set NO_GRAVITY for label or textview

Pooya1

Active Member
Licensed User
Hi
I use text that contain english and arabic string
In android i use NO_GRAVITY for label's gravity and it is ok
Actually for english,text direction is left and for arabic is right
But in iOS I have to either set align to left or right
Do you have idea?
[My problem solved here https://useyourloaf.com/blog/natural-text-alignment-for-rtl-languages/ with other person]
photo_2018-08-17_17-29-32.jpg
 
Last edited:

Pooya1

Active Member
Licensed User
Sorry
The relevant url didn't help me
My text is :
طفل يبلغ من العمر 6 أعوام ورجل يبلغ من العمر 10 أشهر من أجل استئصال الفص الخاص به (وهو الفص العظمي وجزء رئيسي من الفص الصدغي) للتخلص من نوبات الصرع من عمر 4 سنوات ، ولكن فصّه الأيسر يعوض عن المناطق المفقودة من الفص الأيمن. وأخيرًا ، يبقى أدائه البصري والإدراكي ، الذي كان من المرجح أن يتم تدميره ، سليماً!

When surgeons removed one sixth of a child's brain,
here's what happened

By Susan Scutti, CNN

Posted at 1551 GMT (2351 HKT) July 31, 2018
Surgeons removed part of a child's brain for epilepsy and it rewired itself.

The brain surgery that ended boy's epileptic seizures also removed parts of the right hemisphere
His brain rewired itself so that the left hemisphere now performs work normally done by the right
(CNN) — What does a child's brain, which repaired itself after a full third of the right hemisphere was surgically removed, teach us about all brains?
Our developing brains find unique ways to rewire themselves as necessary, suggests a new case study of a nearly 11-year old boy referred to only as "UD" (his privacy is respected by never revealing his true name).

The operation when he was 6 years 10 months old eliminated UD's entire occipital lobe, home of the brain's vision processing center, and most of his temporal lobe, where both visual and auditory signals land and then get sorted. Yet, UD's left hemisphere compensated for any losses on the right side of his brain by assuming the roles of both hemispheres. As a result, both his cognitive and visual function are now intact.

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
Top