Time for action – adding a button to a view
In app.js
add the
following code to add the button to the view:
var button1 = Titanium.UI.createButton({ title:'Button in View', top:10, left:10 }); view.add(button1);
Note
The text on the button is specified by the title argument. Other objects such as a label
or textfield
use the text argument to specify the displayed content. See the Appcelerator documentation http://docs.appcelerator.com/titanium/3.0/# for the appropriate argument for your object.
What just happened?
A button has been added within the view. Note that the position of the button of 10 pixels from the top and 10 pixels from the left is relative to the view and not the window. This is an important and very useful feature of views. You lay out the view within a window, like drawing a picture in a paint package that occupies only part of your display.
Note
Notice how the button butts up against the top-right edge of the view. We didn't specify a size for the button via the...