Author Topic: UILabel Resize Freely truncates content  (Read 3028 times)

Aurigan

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 21
    • View Profile
UILabel Resize Freely truncates content
« on: August 17, 2017, 11:06:54 AM »
A UILabel with 'resize freely' overflow option AND a 'max width' set will truncate content after that max width is hit.

What would be the easiest way to change UILabel 'resize freely' overflow behavior to shrink content once that max width was hit?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Resize Freely truncates content
« Reply #1 on: August 21, 2017, 06:28:33 PM »
Turn off resize freely, change it to shrink content -- and set the label's width/height to what it should be.

Aurigan

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UILabel Resize Freely truncates content
« Reply #2 on: August 24, 2017, 04:21:11 AM »
Hi Aren, thanks for the reply ... the issue is that I need the resize freely behavior - I want to have a label centered but with an icon anchored to the labels right. I guess the alternative hack would be to calc the content width and adjust the icon position in code but would prefer to have a code-free solution to something this standard!

What would your recommendation be for taking this on?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Resize Freely truncates content
« Reply #3 on: August 25, 2017, 12:43:54 AM »
You can simply set the label's pivot point to the right side, then any child you add to that label will be automatically relative to that side, no anchoring needed.

Edit: I think I see what you're asking. Lemme think about it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Resize Freely truncates content
« Reply #4 on: August 25, 2017, 01:02:55 AM »
Turns out this is easier than I thought. Go to UILabel, around line ~1400-1430

  1. else if (mOverflow == Overflow.ResizeFreely)
  2. {
  3.         mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText);

Add the !fits check like so:

  1. else if (mOverflow == Overflow.ResizeFreely)
  2. {
  3.         mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText);
  4.  
  5.         if (!fits && mOverflowWidth != 0)
  6.         {
  7.                 if (--ps > 1) continue;
  8.                 else break;
  9.         }

Aurigan

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UILabel Resize Freely truncates content
« Reply #5 on: August 25, 2017, 04:13:44 AM »
Perfect! Thank you so much :)