---
title: "NGUI动态创建UILabel"
author: "wgcode"
date: "2015-05-13T14:32:23Z"
tags: []
categories: ["移动开发"]
slug: "ngui-uilabel"
draft: false
lastmod: "2015-05-13T14:32:23Z"
id: 2210788
url: "https://tts.iteye.com/blog/2210788"
---

```
using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
    public GameObject testBtn;
    public Font f;
    // Use this for initialization
    void Start()
    {
        UIEventListener.Get(testBtn).onClick += CreatLabel;
    }

    // Update is called once per frame
    void Update()
    {

    }

    void CreatLabel(GameObject go)
    {
        UILabel label = NGUITools.AddChild<UILabel>(gameObject);
        label.trueTypeFont = f;
        label.text = "Test";
    }
}
```