eui.EditableText 使用範例
class Main extends eui.UILayer {
protected createChildren(): void {
super.createChildren();
egret.lifecycle.onPause = () => egret.ticker.pause();
egret.lifecycle.onResume = () => egret.ticker.resume();
egret.registerImplementation('eui.IAssetAdapter', new AssetAdapter());
egret.registerImplementation('eui.IThemeAdapter', new ThemeAdapter());
this.runGame();
}
private async loadResource() {
let loadingView = this.stage.addChild(new LoadingUI()) as LoadingUI;
await RES.loadConfig('resource/default.res.json', 'resource/');
await new Promise(resolve => new eui.Theme('resource/default.thm.json', this.stage).once(eui.UIEvent.COMPLETE, resolve, this));
await RES.loadGroup('preload', 0, loadingView);
this.stage.removeChild(loadingView);
}
private async runGame() {
await this.loadResource();
// --- Edwin 給你最乾淨的程式碼, 從這行以下開始寫喔 ---
// 原本 Label 就可以作為輸入框
const lb = new eui.Label();
lb.text = 'Label Label Label';
lb.type = egret.TextFieldType.INPUT;
lb.border = true;
lb.width = 300;
this.addChild(lb);
// EditableText 可以不用設定 type, 也有 prompt 屬性可以使用, 在沒有文字時可以顯示「請輸入xxx」作為提示
const et = new eui.EditableText();
et.text = 'EditableText EditableText EditableText';
et.border = true;
et.width = 300;
et.prompt = '請輸入你的電話';
this.addChild(et).y = 100;
}
}
沒有留言:
張貼留言