How to remove button border in unity editor

here is my code:

    private void OnGUI()
    {
        GUI.color = Color.white;
        EditorGUILayout.BeginVertical();
        GUILayout.Button("Btn", GetBtnStyle());
        GUILayout.Button("Btn", GetBtnStyle());
        EditorGUILayout.EndVertical();
        GUI.color = Color.white;
    }

    GUIStyle GetBtnStyle()
    {
        var s = new GUIStyle(GUI.skin.button);
        s.fontSize = 20;
        s.alignment = TextAnchor.MiddleLeft;
        s.border.left = 0;
        s.border.top = 0;
        s.border.right = 0;
        s.border.bottom = 0;
        return s;
    }

the output is:
101835-20170914-160531.png

it’s not what i expect, I expect

  • pure white background color
  • two button without margin

how should i do

Try this. Create your own texture for the background of the button and set the margin to 0.

GUIStyle GetBtnStyle()
{
    var s = new GUIStyle(GUI.skin.label);
    Color[] pix = new Color[]{ Color.white };
    Texture2D result = new Texture2D(1, 1);
    result.SetPixels(pix);
    result.Apply();
    s.normal.background = result;
    s.fontSize = 20;
    s.alignment = TextAnchor.MiddleLeft;
    s.margin = new RectOffset(0, 0, 0, 0);
    return s;
}

You can change the color to what you want. You can also use active for on click and hover for on… well you know.

s.active.background = result;
s.hover.background = result;

Hope it helped.