Is there any properties to set the line height/spacing for label and textfield?
Sub SetLineSpace(TF As TextField,LineSpace As Float)
Dim A As AttributedString
A.Initialize(TF.Text,TF.Font,TF.TextColor)
Dim NaObj2 As NativeObject
NaObj2 = NaObj2.Initialize("NSMutableParagraphStyle").RunMethod("new",Null)
NaObj2.RunMethod("setLineSpacing:",Array(LineSpace))
NaObj2.RunMethod("setAlignment:",Array(TF.TextAlignment))
Dim NaObj As NativeObject
NaObj = NaObj.Initialize("NSMutableAttributedString").RunMethod("alloc",Null).RunMethod("initWithAttributedString:",Array(A))
NaObj.RunMethod("addAttribute:value:range:",Array("NSParagraphStyle",NaObj2,NaObj.MakeRange(0,TF.Text.Length)))
Dim NaObj3 As NativeObject = TF
NaObj3.SetField("attributedText",NaObj)
End Sub
Hi,
try this:
B4X:Sub SetLineSpace(TF As TextField,LineSpace As Float) Dim A As AttributedString A.Initialize(TF.Text,TF.Font,TF.TextColor) Dim NaObj2 As NativeObject NaObj2 = NaObj2.Initialize("NSMutableParagraphStyle").RunMethod("new",Null) NaObj2.RunMethod("setLineSpacing:",Array(LineSpace)) NaObj2.RunMethod("setAlignment:",Array(TF.TextAlignment)) Dim NaObj As NativeObject NaObj = NaObj.Initialize("NSMutableAttributedString").RunMethod("alloc",Null).RunMethod("initWithAttributedString:",Array(A)) NaObj.RunMethod("addAttribute:value:range:",Array("NSParagraphStyle",NaObj2,NaObj.MakeRange(0,TF.Text.Length))) Dim NaObj3 As NativeObject = TF NaObj3.SetField("attributedText",NaObj) End Sub
Call this sub after you have all properties set to your TextField. It should also work for labels
Jan
Sub SetLineProperties(TF As Label,LineSpace As Float,MinimumLineHeight As Float, MaximumLineHeight As Float)
Dim A As AttributedString
A.Initialize(TF.Text,TF.Font,TF.TextColor)
Dim NaObj2 As NativeObject
NaObj2 = NaObj2.Initialize("NSMutableParagraphStyle").RunMethod("new",Null)
NaObj2.RunMethod("setLineSpacing:",Array(LineSpace))
NaObj2.RunMethod("setAlignment:",Array(TF.TextAlignment))
NaObj2.RunMethod("setMinimumLineHeight:",Array(MinimumLineHeight))
NaObj2.RunMethod("setMaximumLineHeight:",Array(MaximumLineHeight))
Dim NaObj As NativeObject
NaObj = NaObj.Initialize("NSMutableAttributedString").RunMethod("alloc",Null).RunMethod("initWithAttributedString:",Array(A))
NaObj.RunMethod("addAttribute:value:range:",Array("NSParagraphStyle",NaObj2,NaObj.MakeRange(0,TF.Text.Length)))
Dim NaObj3 As NativeObject = TF
NaObj3.SetField("attributedText",NaObj)
End Sub
Ok, I think LineSpace was the wrong route.
Try this instead (you can set LineSpace to 0):
B4X:Sub SetLineProperties(TF As Label,LineSpace As Float,MinimumLineHeight As Float, MaximumLineHeight As Float) Dim A As AttributedString A.Initialize(TF.Text,TF.Font,TF.TextColor) Dim NaObj2 As NativeObject NaObj2 = NaObj2.Initialize("NSMutableParagraphStyle").RunMethod("new",Null) NaObj2.RunMethod("setLineSpacing:",Array(LineSpace)) NaObj2.RunMethod("setAlignment:",Array(TF.TextAlignment)) NaObj2.RunMethod("setMinimumLineHeight:",Array(MinimumLineHeight)) NaObj2.RunMethod("setMaximumLineHeight:",Array(MaximumLineHeight)) Dim NaObj As NativeObject NaObj = NaObj.Initialize("NSMutableAttributedString").RunMethod("alloc",Null).RunMethod("initWithAttributedString:",Array(A)) NaObj.RunMethod("addAttribute:value:range:",Array("NSParagraphStyle",NaObj2,NaObj.MakeRange(0,TF.Text.Length))) Dim NaObj3 As NativeObject = TF NaObj3.SetField("attributedText",NaObj) End Sub
Jan