core-egret.TextFieldInputType

egret.TextFieldInputType 使用範例


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 給你最乾淨的程式碼, 從這行以下開始寫喔 ---

        const placeholder = '請輸入一段話:';
        const tf = new eui.Label; // eui.Label 可以取代父類 egret.TextField
        tf.type = egret.TextFieldType.INPUT; // 輸入模式
        tf.inputType = egret.TextFieldInputType.TEXT; // 可設置文字模式或密碼模式
        tf.textColor = 0xb2b2b2;
        tf.size = 32; // 文字大小
        tf.width = 500;
        tf.height = 90;
        tf.textAlign = egret.HorizontalAlign.LEFT; // 水平對齊模式
        tf.verticalAlign = egret.VerticalAlign.MIDDLE; // 垂直對齊模式
        tf.border = true; // 顯示邊框
        tf.text = placeholder;
        this.addChild(tf);
        tf.addEventListener(egret.FocusEvent.FOCUS_IN, () => tf.text === placeholder && (tf.text = ''), this); // 成為焦點事件
        tf.addEventListener(egret.FocusEvent.FOCUS_OUT, () => tf.text === '' && (tf.text = placeholder), this); // 失焦事件

    }

}

spacer

沒有留言:

張貼留言