0

我是钛开发的初学者。我需要帮助来设计一个带有文本字段的应用程序,其中包含如下图所示的图像图标。我没有使用应用程序设计器。请帮我在这里输入图片描述

提前致谢

4

1 回答 1

3

create a common input controller

common/input.xml

<View id="container">
    <ImageView id="icon"/>
    <TextField id="input">
</View>

common/input.tss

"#container":{
    height: 50,
    top: 10,
    left: 15,
    right: 15,
    borderColor: 'blue'
}

"#icon":{
    height: 30,
    width: 30,
    left: 10
}

"#input":{
    left: 50,
    right: 10
    //Add your default TextField input here
}

common/input.js

//set controller Style
if ($.args.icon) {
    $.icon.image = $.args.icon;
} else {
    $.icon.visible = false;
    $.input.left = 10;
}

//custom textField style send in inputStyle
if ($.args.inputStyle) {
    _.extend($.input, $.args.inputStyle);
}

$.getValue = function() {
    return $.input.value;
};
$.setValue = function(value) {
    $.input.value = value;
};

Now you can use directly this input style where you want, for exemple on your login screen

login.xml

<Window>
  ..
    <Require id="email" src="common/input" type="view" />
    <Require id="password" src="common/input" type="view" />
  ..
</Window>

login.tss

"#email":{
    icon: '/images/email.png',
    inputStyle: {
        hintText: 'Email Adress'
    }
}
"#password":{
    icon: '/images/password.png',
    inputStyle: {
        hintText: 'Password',
        passwordMask: true
    }
}

and finally you can get the value like this

login.js

var emailValue = $.email.getValue();
var passwordValue = $.password.getValue(); 
于 2017-05-15T08:03:08.893 回答