iOS Question FontScale available in B4i?

chuck3e

Active Member
Licensed User
Longtime User
I can get the font scale used in an Android phone in B4a but the code doesn't work in B4i. Is there a way to get it from an iPhone in B4i?
 

chuck3e

Active Member
Licensed User
Longtime User
Thank you, Semen Matusovskiy. I did find that option for my labels but I need some way to resize text in buttons which don't have that option. One text size doesn't want work in all phones. For instance, I design on my iPhone 6, but installing on an iPhone 8 the text doesn't fit.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
You can scale a font in buttons also (using IOS documentation)
For example, after LoadLayout add following
B4X:
    Dim no As NativeObject = Button1
    Dim titleLabel As NativeObject = no.GetField ("titleLabel")
    titleLabel.RunMethod ("setAdjustsFontSizeToFitWidth:", Array (True))
    titleLabel.RunMethod ("setLineBreakMode:", Array (4)) ' NSLineBreakByTruncatingTail;
Tested in IOS 14.4 simulator only. Probably for early releases it's neccessary to set some additional fields.

A sample ... Button1 has a font size = 100 (very large).
 

Attachments

  • Project.zip
    8.4 KB · Views: 94
Last edited:
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Semen Matusovskiy, thank you so much!!!! That works on my IPhone 6! I'll try it on an iPhone 8 soon. I hope it also works on Labels and TextViews. I'll test that.
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Wishful thinking. Does not work on Labels or TextViews, but works great on Buttons. Thanks again.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Different views have different properties/methods. The sample was for Buttons only. I added Label and TextField.
IMO, to use SizeToFit and to decrease font size in cycle is better.
 
Last edited:
Upvote 0
Top