Change the border's color of a button in Unity3D

一曲冷凌霜 提交于 2019-12-12 22:40:29

问题


I began to work with Unity3D since one month and I'm trying to do an application which contains a menu, composed by a panel and several buttons. At this moment, I'm trying to customize the menu, I change the fill color of the panel and buttons, but until now I could not change the border color of the buttons. There is any way to customize the border's color of the UI buttons? I would appreciate your help. :)


回答1:


No, you can not change just border color. If you use default buttons, take a look at Source image. It is basically a grey square with black borders. So when you change color of image black color remains black. To customize buttons as you want you need either create nested UI elements:

or create sprites with colors you want and replace source image




回答2:


I find nested UI elements to be the easiest way to do something like this. Simple example:

Start out by creating a panel and change the scale until you get the desired size for your button. This will be your "borders".

Next create another panel as a child of the panel you just made and change the scale to be just slightly smaller than your first panel and change the color.

In the Inspector for your panel, add component and type in Button and add it as a component.

Finally, add a text as a child of your panel for a label and you're done.



来源:https://stackoverflow.com/questions/46604643/change-the-borders-color-of-a-button-in-unity3d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!