iOS Question I want TextAlignment in Label Be justified and right

AlfaizDev

Well-Known Member
Licensed User
Code works

But the defect that is
CSBuilder does not work on it


But this code below and found the same work
B4X:
LContant.TextAlignment=3

I remained a small problem I want to align be justified and right
The problem you get in the last line where it is back to the left

He did this code and did not work
B4X:
LContant.TextAlignment=Bit.Or(2,3)

See the image at the bottom

2.png


I want it to be like this
1.png
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub JustifyRTL (cs As CSBuilder) As CSBuilder
    Dim ParaStyle As NativeObject
   ParaStyle = ParaStyle.Initialize("NSMutableParagraphStyle").RunMethod("alloc",Null).RunMethod("init",Null)
    ParaStyle.SetField("alignment",3) 'JUSTIFY
    ParaStyle.SetField("baseWritingDirection", 1) 'RIGHT_TO_LEFT
    cs.As(NativeObject).RunMethod("addAttribute:value:range:", Array("NSParagraphStyle", ParaStyle, cs.As(NativeObject).MakeRange(0, cs.Length)))
    Return cs
End Sub

1625660645619.png
 
Last edited:
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
1625663175470.png

Thank
But why shows so
 

Attachments

  • 1625663098110.png
    1625663098110.png
    13.7 KB · Views: 187
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
This is the new inline casting feature (B4i v7.50). Use Dim no As NativeObject = cs
thanks

You downloaded
But another error appears
This is the way to call
B4X:
Label1.AttributedText=JustifyRTL(cs)
When this paragraph
B4X:
    ParaStyle.SetField("alignment",3) 'JUSTIFY

B4X:
Application_Start
Application_Active
٢
121.5
Error occurred on line: 210 (ContentM)
[<NSMutableParagraphStyle 0x1cf9f9588> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key alignment.
Stack Trace: (
  CoreFoundation       FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 1226784
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 196272
  Foundation           3C682044-3249-3938-8111-F2F12D066D2B + 205328
  result               -[B4INativeObject SetField::] + 132
  result               -[b4i_contentm _justifyrtl:] + 876
  CoreFoundation       FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 1252368
  CoreFoundation       FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 6912
  result               +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
  result               -[B4IShell runMethod:] + 448
result               -[B4IShell raiseEventImpl:method:args::] + 2172
result               -[B4IShellBI raiseEvent:event:params:] + 1580
result               +[B4IDebug delegate:::] + 80
result               -[b4i_contentm _show] + 232
result               -[b4i_indexm _clv1_itemclick::] + 1192
CoreFoundation       FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 1252368
CoreFoundation       FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 6912
result               +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
result               -[B4IShell runMethod:] + 448
result               -[B4IShell raiseEventImpl:method:args::] + 2172
result               -[B4IShellBI raiseEvent:event:params:] + 1580
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
You are correct. It should be:
B4X:
    ParaStyle = ParaStyle.Initialize("NSMutableParagraphStyle").RunMethod("alloc",Null).RunMethod("init",Null)
It works now but I ignore CSBuilder format
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Note that it will override the center alignment that you set in the CSBuilder. You can modify the range, MakeRange(0, cs.Length) to make it skip the beginning.

You modified it to 1
But he appears at the beginning of it
Then closes the program and shows this error
B4X:
MakeRange(1, cs.Length)

B4X:
NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds
 
Upvote 0
Top