Appcelerator Titanium UI textfield with image

414 views Asked by At

I am a beginner in titanium development. I need help to design an app with a textfield contains image icon like below image. i am not using app designer. Please help meenter image description here

Thanks in Advance

1

There are 1 answers

0
Said CHAOUCHE On

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();