- Home /
positioning ui buttons in a scrollview
im creating a contact list for messaging app and i need to generate an unknown number of buttons (each button will pe one contact). i have a convas with a scrollview and the buttons all need to be inside the 'content' part of the scrollview.
heres what i have so far, it successfully creates a button from a prefab but it is stuck in the lower left corner and i dont know how to move it, how can i position them relative to the top middle of the canvas/scrollview?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class contact_list_creation : MonoBehaviour {
// Use this for initialization
public GameObject message_button;
public Transform root;
void Start () {
GameObject b1 = Instantiate(message_button, Vector3.zero, Quaternion.identity, root);
}
}
Answer by Matthew_Ostil · Nov 21, 2018 at 07:00 PM
Have a look at this Tutorial. There is definitely a way to have everything at the top and as new elements are added, the content rect increases in size allowing for scrolling.
Your answer
Follow this Question
Related Questions
Making a previously selected UI button interactable again 1 Answer
Passing through a GameObject/Function to a button's OnClick 1 Answer
UI Buttons in prefab not working at all 1 Answer
Making a button appear on a specific state? 1 Answer
Weird behaviour when trying to dynamically create buttons 0 Answers