iOS Question Space pad a label

rfresh

Well-Known Member
Licensed User
How can I add some space padding to the end of my Label text?

I enabled the iStringUtils lib but .Space() still had a red line under it.

B4X:
LabelTest.Text = LabelTest.Text & Space()
Thank you...
 

emexes

Well-Known Member
Licensed User
What is the aversion to:
B4X:
LabelTest.Text = LabelTest.Text & "     "    'however much space you need
On a related note: you can center the text within the label

upload_2019-7-28_2-58-47.png
 
Last edited:

rfresh

Well-Known Member
Licensed User
I don't want it centered. I'd like some padding on the end with the text set to flush right.
 

emexes

Well-Known Member
Licensed User
I don't want it centered. I'd like some padding on the end with the text set to flush right.
Fair enough. Ignore the related note bit. But now that I'm here... on another related note aka potential alternative route to your goal:

I've always just pulled back the right-hand side edge of the label a little, to leave a space between it and whatever it is labelling.
 

rfresh

Well-Known Member
Licensed User
Yes, however my label has a background color and the last letter of the label text is right up against the label right side end and looks bad. Thus, I still need a way to add a space or two at the end of my text.
 

emexes

Well-Known Member
Licensed User
Yes, however my label has a background color and the last letter of the label text is right up against the label right side end and looks bad. Thus, I still need a way to add a space or two at the end of my text.
Understood. The ampersand and literal spaces should do the trick.

If there's a risk of adding spaces multiple times, then adding a Trim should work eg:
B4X:
RandomLabel.Text = RandomLabel.Text.Trim & "    "
 

rfresh

Well-Known Member
Licensed User
My label is set to flush text right. Your example doesn't work. I don't see any spaces...the last letter of my label text is right up against the right side of the label itself.
 

Brandsum

Well-Known Member
Licensed User
What you can do is you can add that label inside a panel and reduce the width of the label from right side. Then set the panel background color same as label background color.

If you want to use this kind of label in many places then it's better to create a custom view and use that wherever you want.
 

rfresh

Well-Known Member
Licensed User
Wow that looks like a lot of work to accomplish such a simple task. I'll just have to live with it.

Thank you however.
 

emexes

Well-Known Member
Licensed User
My label is set to flush text right. Your example doesn't work. I don't see any spaces...the last letter of my label text is right up against the right side of the label itself.
You're right. I did think originally that the question was a bit too easy :-/

I assume you've gone with the label-underneath solution, but irregularities like this irk me senseless. So in case the issue arises again, I've done a bit of mucking around in search of easier solutions.

If you only need a little bit of space, then you could set the border color to the same as the background color, and set the border width to the amount of padding you require... but naturally, that didn't work either - sure, the border appears, but the text doesn't budge, it gets covered by the border. I kid you not. But it's inadvertently useful - what you could do is set the border to be the width of a very narrow character eg a full stop "." and then use that character to stop the padding spaces from being trimmed from the end of the string, eg Label.Text = "Customer ."

Kludgy, I know, but it works (on an iPhone 5s).

I have another idea too, which is less kludgy but still a bit like, wtf?!?! :)
 

emexes

Well-Known Member
Licensed User
Surprisingly, this works. Optimists Of The World, Unite!

It is obvious after the event - you can thwart the trailing-spaces trimming with a Mongolian Vowel Separator. Again, I kid you not. Don't know why I didn't suggest it in my first post ;-)
B4X:
Label1.Text = "Test   " & Chr(0x180E)
Sleep(1000)
Label1.Text = "Test  " & Chr(0x180E)
Sleep(1000)
Label1.Text = "Test " & Chr(0x180E)
Sleep(1000)
If you're not comfortable using that obscure character, you could choose something more plausible from this list:

http://jkorpela.fi/chars/spaces.html

upload_2019-7-28_14-34-39.png


I would shy away from that last one, though - it looks suspiciously like the Unicode Byte Order Mark character. We're in crazy territory already, so let's not be pushing our luck.

:)
 

rfresh

Well-Known Member
Licensed User
How excellent of you! BOTH of your solutions work fine!

Thank you so much for the extra effort!
 

emexes

Well-Known Member
Licensed User
On a totally unrelated note: this thread first caught my eye because the title contained the words "Space pad".

In a previous life as a delivery driver, I once had a parcel addressed to "2427 Gembrook Launching Pad" which seemed a bit unlikely because Gembrook is a small town with a regular steam train service, and I was pretty sure that if it had a rocket launching pad then I would know about it.

After a few seconds, I realised it was actually addressed to "2427 Gembrook Launching Place Road" but the label printing software couldn't handle that long a line, so it removed some characters near the end of the line to make it fit.



Sadly, the legs-out-the-window fun has been verboten after a mini-bus driver raced the steam train to a road crossing, and lost.
 
Last edited:
Top