NGUI的輸入框的校驗(input filed script)
阿新 • • 發佈:2018-03-15
component inf 添加 tco 輸入框 body .com wake wak
一,我們制作一個輸入框,右鍵添加Sprite ,給Sprite添加一個child的label,然後給Sprite添加一個box collider,接著添加input filed script,將label綁定到UIInput的label中,結果如下圖:
二,看上圖,我們發現UIInput有三個屬性,Character Limit,Input Type和Validation來控制輸入類型
Input Type:輸入類型(standard)標準的,(AutoCorrect)自動修正,(Password)密碼
Validation:輸入類型限制
Character Limit:輸入字符數限制,長度
三,我們寫腳本來限制輸入規則,如下
using UnityEngine; using System.Collections; public class AgeLimit : MonoBehaviour { private UIInput input; private void Awake() { input = this.GetComponent<UIInput>(); } public void OnAgeValueChange() { string value = input.value;int valueint = int.Parse(value); if (valueint < 18) { input.value = "18"; } if (valueint > 120) { input.value = "120"; } } }
UIInput的設置如下:
NGUI的輸入框的校驗(input filed script)