LabelField, PrefixLabel, SelectableLabel
示例程序 | |
---|---|
说明 | 生成标签区域 |
用法
LabelField
主要用于显示只读的信息,生成的区域包含两个部分,一个是标记这个标签区域的标签(即标签的名称),另一个是实际标签区域(即标签的具体内容),其用法如下:
public static void LabelField(string label, params GUILayoutOption[] options);
public static void LabelField(string label, GUIStyle style, params GUILayoutOption[] options);
public static void LabelField(GUIContent label, params GUILayoutOption[] options);
public static void LabelField(GUIContent label, GUIStyle style, params GUILayoutOption[] options);
public static void LabelField(string label, string label2, params GUILayoutOption[] options);
public static void LabelField(string label, string label2, GUIStyle style, params GUILayoutOption[] options);
public static void LabelField(GUIContent label, GUIContent label2, params GUILayoutOption[] options);
public static void LabelField(GUIContent label, GUIContent label2, GUIStyle style, params GUILayoutOption[] options);
PerfixLabel
主要用于标记控制区域的名称,也就是 LabelField
的前一个部分。其用法如下:
public static void PrefixLabel(string label, GUIStyle followingStyle = "Button");
public static void PrefixLabel(string label, GUIStyle followingStyle, GUIStyle labelStyle);
public static void PrefixLabel(GUIContent label, GUIStyle followingStyle = "Button");
public static void PrefixLabel(GUIContent label, GUIStyle followingStyle, GUIStyle labelStyle);
SelectableLabel
则是用于生成可供用户复制、粘贴的标签,其用法如下:
public static void SelectableLabel(string text, params GUILayoutOption[] options);
public static void SelectableLabel(string text, GUIStyle style, params GUILayoutOption[] options);
参数
label
位于标签之前的标签名称。
label2 / text
显示的标签内容。
style
(可选)由 GUIStyle
类型定义的 GUI 样式。
options
(可选)用于指定额外的布局属性,该参数将覆盖默认样式。
followingStyle
labelStyle
示例
public override void OnInspectorGUI () {
EditorGUILayout.LabelField ("This is the label of this label field.");
EditorGUILayout.LabelField (
"This is the label of this label field.",
"This is the content of this label field"
);
EditorGUILayout.PrefixLabel ("This is a prefix label field.");
_target.Value = EditorGUILayout.IntField (_target.Value);
EditorGUILayout.SelectableLabel ("This is a selectable label that you can copy / paste as you like.");
}
编译结果如下: