- Home /
New UI Scrollview with changing content
Hello all,
I am looking for a good solution to populating a list of servers to connect to from a client. I want a scrollable list of buttons. Using the old UI, I could use a for loop to generate the buttons inside a scrollview. Is there anything similarly easy in the new UI system? I'm leaning toward using a panel as the scrollview content, dynamically resizing the panel's height depending on the number of servers to connect to (= the number of buttons) and the resolution, and somehow dynamically creating the buttons. I'm not yet sure how anchoring figures into creating the buttons.
Is there a simple feature built into the new UI to achieve this task, or subsets of this task?
Answer by Kiwasi · Nov 04, 2014 at 07:09 PM
The layouts components will help. I'm in the process of building a YouTube tutorial to do just that. Will post back tonight when it's up.
The basic strategy is to iterate over your collection and Instantiate a prefab for each button. Then set the parent to a panel that has a vertical layout group. You can adjust sizing of each button using a layout element.
Layout group, eh? That sounds perfect. I'll look into it.
Layout groups did the trick. Thanks for the tip. I found out from another question on this website that in order to get at the documentation for the new UI you have to do Help -> Unity manual from the editor. This opens a local copy of documentation that contains info not available from the web (probably due to the beta nature of the UI). Perusing this manual gave me all the details I needed.
There is also an online copy of the docs here
http://docs.unity3d.com/460/Documentation/$$anonymous$$anual/UISystem.html