0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Unity】UIToolkitのTextFieldでPlaceholderを設定する3つの方法

0
Posted at

はじめに

UIToolkitのTextFieldではPlaceholderを設定できる
ただ、TextField.placeholderは無いので、いつかまた調べた時のために記事として残しておく

https://docs.unity3d.com/ja/2023.2/Manual/UIE-uxml-element-TextField.html
TextFieldの詳細については上記ドキュメントを読むこと

1. スクリプトからの指定

以下のスクリプトで指定できる

var textField = new TextField();
textField.textEdition.placeholder = "Enter text here";
root.Add(textField);

textEditionは、テキストの編集機能へのアクセスのためにつくらたITextEditionインターフェース
他のInputField系のElementも、これを通して設定を変更できる

2. UI Builderからの指定

UI BuilderでTextFieldを配置すると、Inspectorに Placeholder Textという設定欄が表示される
ここから表示したいPlaceholderを設定できる
スクリーンショット 2025-12-02 23.39.03.png

3. UXMLからの指定

<engine:TextField label="Text Field" placeholder-text="filler text" name="textField" />

UXMLのTextFieldでは、placeholder-textとして文字列を指定できる

おまけ

placeholderの見た目をUSSから指定したいときは、 .unity-base-text-field__input--placeholderで変更できる

.unity-base-text-field__input--placeholder {
    color: #333333;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?