1
NGUI 3 Support / Get UILabel Y Size?
« on: January 14, 2016, 12:36:46 PM »
Hi there..
I want to change the position of UILabels in my Scrollview, to make them sit directly under each other.
The UILabels can be rewritten by UIInput, and so they can change in height (cause multiline).
So the Question:
How to get the current Height of a Label, to place the next directly under it.
Current approach:
Problem:
if Label1 has a Widget Y size of 48, Label2 is placed far below it (around 200)... instead of 48 :/
I want to change the position of UILabels in my Scrollview, to make them sit directly under each other.
The UILabels can be rewritten by UIInput, and so they can change in height (cause multiline).
So the Question:
How to get the current Height of a Label, to place the next directly under it.
Current approach:
- using UnityEngine;
- using System.Collections;
- public class UISetup_ReloadTextView : MonoBehaviour {
- private int ChildCounts, NewYPosition;
- private Transform CurrentChild;
- public void UpdateView(){
- ChildCounts = transform.childCount;
- NewYPosition = 0;
- GetComponent<UIScrollView>().ResetPosition();
- for(int looper1 = 0; looper1 < ChildCounts; looper1 ++){
- CurrentChild = transform.GetChild(looper1);
- NewYPosition -= (int)(CurrentChild.GetComponent<UILabel>().relativeSize.y * CurrentChild.localScale.y);
- }
- GetComponent<UIScrollView>().ResetPosition();
- }
- }
if Label1 has a Widget Y size of 48, Label2 is placed far below it (around 200)... instead of 48 :/