语言English
  • C#

GUI.TextField

声明

public static string TextField(Rect position, string text);

声明

public static string TextField(Rect position, string text, int maxLength);

声明

public static string TextField(Rect position, string text, GUIStyle style);

声明

public static string TextField(Rect position, string text, int maxLength, GUIStyle style);

参数

position 屏幕上用于文本字段的矩形。
text 要编辑的文本。此函数的返回值应分配回字符串,如示例所示。
maxLength 字符串的最大长度。如果省略,用户可以无限期地输入。
style 要使用的样式。如果省略,则使用当前 GUISkin 中的 textField 样式。

返回值

string 已编辑的字符串。

描述

创建一个单行文本字段,用户可以在其中编辑字符串。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public string stringToEdit = "Hello World";

void OnGUI() { // Make a text field that modifies stringToEdit. stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25); } }

Did you find this page useful? Please give it a rating: