iOS Question Space pad a label

Discussion in 'iOS Questions' started by rfresh, Jul 27, 2019.

  1. rfresh

    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.

    Code:
    LabelTest.Text = LabelTest.Text & Space()
    Thank you...
     
  2. emexes

    emexes Well-Known Member Licensed User

    What is the aversion to:
    Code:
    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: Jul 27, 2019
  3. rfresh

    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.
     
  4. emexes

    emexes Well-Known Member Licensed User

    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.
     
  5. rfresh

    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.
     
  6. emexes

    emexes Well-Known Member Licensed User

    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:
    Code:
    RandomLabel.Text = RandomLabel.Text.Trim & "    "
     
  7. rfresh

    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.
     
  8. Brandsum

    Brandsum Active 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.
     
  9. rfresh

    rfresh Well-Known Member Licensed User

    Where can I read up on building custom views to do that?
     
  10. Brandsum

    Brandsum Active Member Licensed User

  11. rfresh

    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.
     
  12. emexes

    emexes Well-Known Member Licensed User

    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?!?! :)
     
  13. emexes

    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 ;-)
    Code:
    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.

    :)
     
  14. rfresh

    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 likes this.
  15. emexes

    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.

    [​IMG]

    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: Jul 28, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice