首页 > 解决方案 > How can I make a GUI.Toggle font size and color to be bigger and in black like the example in the screenshot?

问题描述

The script is EditorWindow type:

What I did inside OnGUI:

void OnGUI()
    {
        GUIStyle myToggleStyle = new GUIStyle(GUI.skin.toggle);
        myToggleStyle.fontSize = 14;

        Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
        myToggleStyle.font = myFont;
        myToggleStyle.normal.textColor = Color.black;

        GUI.Toggle(new Rect(5, 10, 200, 60), false, "Select All", myToggleStyle);
    }

The screenshot show the result of my toggle at the top the "Select All" and under it the toggle how I want my one to be the same. A bit bigger but same color and font. If the bottom toggle size is 11 or 12 then my one should be 13 or 14. But as long as I make my toggle font size bigger the color is not the same as the bottom one and both are black.

The bottom one is created by EditorGUILayout.BeginToggleGroup and EditorGUILayout.EndToggleGroup but I want to make a single one not a group.

Toggle

The main goal is to make a single toggle just like the bottom one by size and color.

标签: unity3d

解决方案


我认为您只需要将字体样式设置为粗体:

myToggleStyle.fontStyle = FontStyle.Bold;

推荐阅读