Display both text and image on a selection grid

I would like to display both text and images on selection grid items, however, it seems that Unity does not support this.

It seems to be a quite simple problem, but still I cannot find any viable solution so far, and it took me a lot of time looking around for one.

Anyone has a idea for this please help me out.

Use the overload of SelectionGrid that accepts GUIContent. GUIContents have both text and images.


using UnityEngine;
using System.Collections;

public class Demo : MonoBehaviour
    public int selected = 0;
    public int columns = 3;
    public GUIContent[] contents; // Set it up in inspector etc

    void OnGUI()
        selected = GUILayout.SelectionGrid(selected, contents, columns);

You can also make use of gui styles to tailor the appearance and layout of the text and images within grid items.

Thank you for your help. It seems that GUIContent actually use image as its icon, rather than its background. I would like to display text inside the images, however, I only can find 4 options to layout image and text, they are: ImageAbove, ImageLeft, TextOnly, and ImageOnly.

Is there a property which act like background image in GUIStyle?