I have a list of contacts. I need to create a scrollable list of buttons that are created dynamically so I can add each contact name as the button text. How would I do this all in code? My biggest concern is making sure the sizes stay consistent. I haven't had to do that in code before.
EDIT:
And here is the code to add the buttons to this:
for (int i = 0; i < count; i++)
{
if (i > 0)
crt.sizeDelta = new Vector2(crt.sizeDelta.x, crt.sizeDelta.y + initHeight);
GameObject contactButton = Instantiate(Resources.Load("Contact Button")) as GameObject;
contactButton.transform.parent = contactsList.transform;
contactButton.GetComponentInChildren().text = names[i];
}
No comments:
Post a Comment