Author Topic: How to handle resizing label in scrollview  (Read 5493 times)

Radagan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
How to handle resizing label in scrollview
« on: May 23, 2014, 12:45:53 AM »
Hi Tasharen,

Basically, I am trying to get a scrollview that contains a single label to scroll when the label resizes height. The text in the label is set in code. I can't seem to find a way to get it to work.

I can get the label to resize properly with advanced anchors and "resize height" selected, and the vertical scroll bar appears and resizes properly. The problem is when you move the scroll bar the text bobs a little, but you does not scroll down with the scroll bar. 

Any ideas?

-R.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to handle resizing label in scrollview
« Reply #1 on: May 23, 2014, 03:52:24 PM »
I recently had to do this for a video... http://www.youtube.com/watch?v=otqY_Mx11yw

Simply call scroll view's UpdatePosition() after changing the text. I've done it inside the TypewriterEffect for that video.

Radagan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: How to handle resizing label in scrollview
« Reply #2 on: May 25, 2014, 01:44:37 AM »
Excellent! Thank you very much.  8)

manumoi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: How to handle resizing label in scrollview
« Reply #3 on: December 05, 2014, 05:30:46 PM »
Hello I have a slightly similar issue except that I have several labels and sprites after each others in my scrollview i.e.:

backgroundSprite //the one directly attached to the scrollview, size adjusted to itemSprite.Top and Label4.bottom
-- ItemSprite
-- titleBar1
-- Label1
-- titleBar2
-- Label2
-- TitleBar3
-- Label3
-- TitleBar4
-- Label4

the top position of each element is obtained from the bottom of the upper element, using the anchor system.
TitleBar have fixed sizes
Label values can be changed programmatically since they come from a data structure. So label heights are obtained by putting label's Overflow parameter to ResizeHeight and their bottomAnchor values to none.

First i thought that everything was ok but i eventually noticed that sometimes the height of one of my label doesn t adjust. Tried different variants of updatePosition, resetPosition, InvalidateBounds (not sure what the last one does) but can't figure out how to fix the bug.

Even stranger, when i m in editor mode with the interface playing and i go to the anchor system of the UILabel that didn t adjust well, just putting a value (without validating it) in the bottomAnchor absolute field will trigger the height update to the correct value. So there must be some update occurring here.


Latest of my numerous code attempts below where I reinitialize the labels from a data structure

  1.     public void init(Content content)
  2.     {
  3.         this.content = content;
  4.         this.scrollView.ResetPosition();
  5.         this.contentPictureSprite.spriteName = content.Id + ".icon";  //itemSprite
  6.         this.contentPictureSprite.keepAspectRatio = UIWidget.AspectRatioSource.Free;
  7.         this.contentPictureSprite.MakePixelPerfect();
  8.         float ar = (float)this.contentPictureSprite.width / (float)this.contentPictureSprite.height;
  9.         this.contentPictureSprite.aspectRatio = ar;
  10.         this.contentPictureSprite.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnWidth;
  11.         this.contentPictureSprite.leftAnchor.relative = 0f;
  12.         this.contentPictureSprite.leftAnchor.absolute = 0;
  13.         this.contentPictureSprite.rightAnchor.relative = 1f;
  14.         this.contentPictureSprite.rightAnchor.absolute = 0;
  15.         this.descriptionLabel.text = content.Description; // label1
  16.         this.scrollView.UpdatePosition();
  17.         this.characteristicsLabel.text = content.Characteristics; // label2
  18.         this.scrollView.UpdatePosition();
  19.         this.availabilityLabel.text = content.Availability;  // label3
  20.         this.scrollView.UpdatePosition();
  21.         this.audienceLabel.text = content.Audience; // label4
  22.         this.scrollView.UpdatePosition();
  23.         /*this.scrollView.InvalidateBounds();
  24.         this.scrollView.ResetPosition();
  25.         this.scrollView.UpdatePosition();*/
  26. }
  27.  

I have attached a screenshot (left when the issue occurs, right when it automatically adjust once i enter a value in the bottomAnchor.absolute field)

Any idea what I am missing?
 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to handle resizing label in scrollview
« Reply #4 on: December 07, 2014, 12:13:48 AM »
Whenever you alter anchors like that you must call widget.ResetAndUpdateAnchors().