Changing the label style on a text field in EditorGUILayout

So when using EditorGUILayout in this manner:

GUIStyle SectionNameStyle = new GUIStyle();
SectionNameStyle.fontSize = 35;
SectionName = EditorGUILayout.TextField(“Section Name”, SectionName, SectionNameStyle);

The actual text field part of the text field is changed to font size 35 but the label is still the default. How do I change the label’s style? Looking at the documentation, the constructor only takes a string or a GUIContent (?) for the label.

(This post should be in Extensions & OnGUI.)

You’ll need to draw the label separately. For example:

GUIStyle SectionNameStyle = new GUIStyle();
SectionNameStyle.fontSize = 35;
EditorGUILayout.BeginHorizontal();
try {
    EditorGUILayout.LabelField("Section Name", SectionNameStyle);
    SectionName = EditorGUILayout.TextField(SectionName, SectionNameStyle);
} finally {
    EditorGUILayout.EndHorizontal();
}
1 Like