- Home /
Question by
unity_qrj_5UYMolP0jA · Feb 25, 2021 at 12:32 PM ·
c#scripting problemui
Editing UIElements Label through code and alignment
Is there a way I can shorten the width of the label on this UIElement IntegerField through code, or would I need to use USS? Also, I'd like to increase the size of the input field to a fixed width.
inputfield.png
(8.3 kB)
inputfield2.png
(6.1 kB)
Comment
Best Answer
Answer by andrew-lukasik · Feb 25, 2021 at 01:15 PM
Yes. That would probably be something like this:
var integerField = new UnityEditor.UIElements.IntegerField();
// increase the size of the input field to a fixed width:
int fixedWidth = 100;
integerField.style.maxWidth = fixedWidth;
integerField.style.minWidth = fixedWidth;
// shorten the width of the label:
foreach( var ve in integerField.Children() )
if( ve is UnityEngine.UIElements.Label )
ve.style.maxWidth = 30;