Jeff Batt 
eLearning Brothers 
Appelerator Titanium - Create Mobile Apps Using 
Javascript, CSS & XML: Product Development Part Manager 
1 
Jeff Batt 
Kinetic Media 
Owner / Head Trainer 
jeff@kinetic-media.com 
Contact info: jeff@kinetic-media. 
com
www.kinetic-media.com 
www.youtube.com/jeffbatt01 twitter.com/jeffbatt01 
Access Files 
Connect with me: 
(www.kinetic-media.com) 
Approach: 
• More hands on. Walk you through how to use the software instead of just talking about it. 
• Hard to tell who is on what level so I start from the beginning on the basic level. 
• Additional tutorials can be found free on my blog and YouTube channel.
Differences between Titanium & Phonegap 
What is the difference between PhoneGap & Titanium? 
- The basic answer is PhoneGap uses straight HTML so you have to use your own elements in 
CSS or use some library like jQuery but it does not allow you to use native elements like tabs, 
table views and other elements.
Differences between Titanium & Phonegap 
jQuery Mobile & Phonegap 
What is the difference between PhoneGap & Titanium? 
- The basic answer is PhoneGap uses straight HTML so you have to use your own elements in 
CSS or use some library like jQuery but it does not allow you to use native elements like tabs, 
table views and other elements.
Differences between Titanium & Phonegap 
jQuery Mobile & Phonegap Appcelerator Titanium 
What is the difference between PhoneGap & Titanium? 
- The basic answer is PhoneGap uses straight HTML so you have to use your own elements in 
CSS or use some library like jQuery but it does not allow you to use native elements like tabs, 
table views and other elements.
Alloy VS Classic 
Alloy Classic 
VS 
Alloy vs Classic? 
- Alloy is a new language introduced by Appcelerator. It uses the MVC model. Although both 
languages can produce the same thing Alloy can do it with less code (most of the times). It 
also separates your code more for easier maintainability. 
- It does come down to preference, which way you prefer to code.
Alloy - MVC 
index.xml 
index.tss index.js 
MVC 
- Alloy uses uses an MVC model. This separates the code to make it more maintainable. 
- The model is used in the index.xml to define the content. 
- The view is used in the index.tss to control the look of the elements. The nice thing about 
this is you can define different visuals based on device, and OS. 
- The controller is within the index.js. This controls what happens with elements are clicked 
on or logic for the app.
Starting a New Project 
Starting a New Project 
- To start a new project simply click on File > New > Mobile Project
Starting a New Project 
Alloy: Classic: 
Type of Project 
- Depending on the type of project you want you can select one of the default templates or 
just select default to start your own.
Creating a Window 
Classic Code: 
app.js 
//Establish the window and color 
var window = Titanium.UI.createWindow({ 
backgroundColor:'red' 
}); 
//Open the window 
window.open(); 
Classic: 
//Establish the window and color 
var window = Titanium.UI.createWindow({ 
backgroundColor:'red' 
}); 
//Open the window 
window.open();
Creating a Window 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container"> 
</Window> 
</Alloy> 
index.tss 
".container": { 
backgroundColor:"red" 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"red" 
}
Windows and Views 
Windows vs Views 
- There can only be 1 window open and any time but you can establish a numerous views 
within the window. You can either add elements to your window or to any view to group them 
together and then you can position your views form there.
Windows and Views 
Window 1 
Windows vs Views 
- There can only be 1 window open and any time but you can establish a numerous views 
within the window. You can either add elements to your window or to any view to group them 
together and then you can position your views form there.
Windows and Views 
Window 1 
View 1 
View 2 
View 3 
Windows vs Views 
- There can only be 1 window open and any time but you can establish a numerous views 
within the window. You can either add elements to your window or to any view to group them 
together and then you can position your views form there.
Different Types of Views 
Window 1 
Image View 
Table View 
Scroll View 
Different Types of Views 
- Like we will learn there are many different types of views you can add or you can have just a 
normal view.
Analogy - Creating Objects then Adding to Window 
Get the Actor 
Get the Object 
var actor = Ti.UI.createView({ 
}); 
Compare to Actors on Stage/Camera 
- Just like getting an actor ready for the stage defining objects to place on the stage is 
similar. You first define which actor you want to use for your “production”. For the code you 
choose from the different objects (actors) available and then wrap them in a variable most of 
the time using the Ti.UI.create... 
- This isn’t all you need to do. In order for them to be ready you need to define some 
attributes of how you want them to look/act.
Analogy - Creating Objects then Adding to Window 
Add Attributes to Actor 
- Makeup 
- Costume 
- etc 
var actor = Ti.UI.createView({ 
backgroundColor:'red', 
width:100, 
height:100, 
top:20 
}); 
Add Attributes to the Object 
- Width 
- Height 
- etc 
Compare to Actors on Stage/Camera 
- Just like an actor cannot just walk off the street and portray the character you have in your 
mind. You need to define some attributes with them. Such as costume, make up and other 
things. In this same way you add attributes to your objects such as width, height and others. 
- This defines what the actor will look like and how they will appear but it still does not place 
them where they need to be.
Analogy - Creating Objects then Adding to Window 
Add the actor to the stage/ 
camera 
Add object to the window or view 
var actor = Ti.UI.createView({ 
backgroundColor:'red', 
width:100, 
height:100, 
top:20 
}); 
window.add(actor); 
image.addEventListener('click', function(){ 
alert('This is a test'); 
}) 
Compare to Actors on Stage/Camera 
- The final step is to place the actor on stage or on camera. This is where they need to be to 
be viewed by the audience. If they are not on the camera then your end audience will not see 
them. 
- After this is done you then define what the actor should do with the script or in the case of 
coding javascript or adding event listeners.
Analogy - Creating Objects then Adding to Window 
<Alloy> 
<Window class="container"> 
<ImageView id="actor" onClick="doClick" 
image="images/Checkmark.png" /> 
</Window> 
</Alloy> 
XML - Get the Actor 
TSS - Define Attributes 
"#actor":{ 
top: 10, 
width: 260, 
height: 95 
function doClick(e) { 
//Tell the actor what to do 
} 
JS - Script what the actor does 
} 
Compare to Actors on Stage/Camera 
- Alloy works the same. You add the object in the XML then add attributes in the TSS file and 
finally add the script within the JS file.
Creating a View 
Classic Code: 
app.js 
//Create the view and it's attributes 
var view1 = Ti.UI.createView({ 
backgroundColor:'red', 
width:100, 
height:100, 
top:20 
}); 
//Add the view to the window or view 
window.add(view1); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'white' 
}); 
//Create the view and it's attributes 
var view1 = Ti.UI.createView({ 
backgroundColor:'red', 
width:100, 
height:100, 
top:20 
}); 
//Add the view to the window or view 
window.add(view1); 
window.open();
Creating a View 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container"> 
<View id="view" /> 
</Window> 
</Alloy> 
index.tss 
".container": { 
backgroundColor:"white" 
}, 
"#view": { 
backgroundColor:"red", 
width: 50, 
height: 50, 
top: 10 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<View id="view" /> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#view": { 
backgroundColor:"red", 
width: 50, 
height: 50, 
top: 10 
} 
or 
index.xml: 
<Alloy> 
<Window class="container"> 
<View id="view" backgroundColor="red" width="50" height="50" /> 
</Window> 
</Alloy>
Adding Objects to a View 
Classic Code: 
app.js 
//Create the view and it's attributes 
var view1 = Ti.UI.createView({ 
backgroundColor:'red', 
width:100, 
height:100, 
top:20 
}); 
//Create the object and its attributes 
var view2 = Ti.UI.createView({ 
backgroundColor:'black', 
width: 20, 
height: 20, 
top: 10 
}); 
//Add the second object to the view not the window 
view1.add(view2); 
//Add the view to the window or view 
window.add(view1); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Create the view and it's attributes 
var view1 = Ti.UI.createView({ 
backgroundColor:'red', 
width:100, 
height:100, 
top:20 
}); 
//Create the object and its attributes 
var view2 = Ti.UI.createView({ 
backgroundColor:'black', 
width: 20, 
height: 20, 
top: 10 
}); 
//Add the second object to the view not the window 
view1.add(view2); 
//Add the view to the window or view 
window.add(view1); 
window.open();
Adding Objects to a View 
Alloy Code: 
index.xml 
<View id="view"> 
<View id="view2"></View> 
</View> 
index.tss 
"#view": { 
backgroundColor:"red", 
width: 50, 
height: 50, 
top: 10 
} 
"#view2": { 
backgroundColor:"black", 
width: 20, 
height: 20, 
top: 5 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<View id="view"> 
<View id="view2"></View> 
</View> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#view": { 
backgroundColor:"red", 
width: 50, 
height: 50, 
top: 10 
} 
"#view2": { 
backgroundColor:"black", 
width: 20, 
height: 20, 
top: 5 
}
Adding Content to Views - Creating Labels 
Classic Code: 
app.js 
//This is the code to create a label 
var label1 = Ti.UI.createLabel({ 
color:'#999', 
text:'This is a text', 
font:{fontSize:20, fontfamily:'Helvetica Neue'}, 
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, 
width: Ti.UI.SIZE, height: Ti.UI.SIZE, 
}) 
//You then add your label to the window or view 
window.add(label1) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//This is the code to create a label 
var label1 = Ti.UI.createLabel({ 
color:'#999', 
text:'This is a text', 
font:{fontSize:20, fontfamily:'Helvetica Neue'}, 
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, 
width: Ti.UI.SIZE, height: Ti.UI.SIZE, 
}) 
//You then add your label to the window or view 
window.add(label1) 
window.open();
Adding Content to Views - Creating Labels 
Alloy Code: 
index.xml 
<Label id="label1">This is a text</Label> 
index.tss 
"#label1": { 
top: 30, 
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER 
} 
"Label": { 
width: Ti.UI.SIZE, 
height: Ti.UI.SIZE, 
color: "#000" 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Label id="label1">This is a text</Label> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#label1": { 
top: 30, 
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER 
} 
"Label": { 
width: Ti.UI.SIZE, 
height: Ti.UI.SIZE, 
color: "#000" 
}
Adding Content to Views - Creating Labels 
Alloy Code (Option 2): 
index.xml 
<Label id="label1" 
color="#900" 
text="A simple label" 
textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER" 
top="30" 
width="Ti.UI.SIZE" height="Ti.UI.SIZE" /> 
Alloy (Option 2): 
index.xml: 
<Alloy> 
<Window class="container"> 
<Label id="label1" color="#900" shadowColor="#aaa" text="A simple label" 
textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER" 
top="30" width="Ti.UI.SIZE" height="Ti.UI.SIZE" /> 
</Window> 
</Alloy>
Adding Content to Views - Image View 
Classic Code: 
app.js 
//Create the image and point to the file in a folder 
var image = Ti.UI.createImageView({ 
image: 'images/Checkmark.png', 
//You can also add position or other attributes 
}) 
//Add the image to the window or view 
window.add(image); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Create the image and point to the file in a folder 
var image = Ti.UI.createImageView({ 
image: 'images/Checkmark.png', 
//You can also add position or other attributes 
}) 
//Add the image to the window or view 
window.add(image); 
window.open();
Adding Content to Views - Image View 
Alloy Code: 
index.xml 
<ImageView id="image" image="images/Checkmark.png" /> 
index.tss 
"#image": { 
} 
**NOTE** 
Alloy assets have to be within the assets folder 
//NOTE: Alloy assets have to be within the assets folder 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<ImageView id="image" image="images/Checkmark.png" /> 
</Window> 
</Alloy> 
index.tss: 
(Optional) 
"#image": { 
}
Adding Event Listeners 
Classic Code: 
app.js 
var image = Ti.UI.createImageView({ 
image: 'images/Checkmark.png', 
}) 
window.add(image); 
image.addEventListener('click', function(){ 
alert('This is a test'); 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var image = Ti.UI.createImageView({ 
image: 'images/Checkmark.png', 
}) 
window.add(image); 
//You can add an event listener to any view, window or object 
image.addEventListener('click', function(){ 
alert('This is a test'); 
}) 
window.open();
Adding Event Listeners 
Alloy Code: 
index.xml 
<ImageView id="image" onClick="doClick" image="images/ 
Checkmark.png" /> 
index.js 
function doClick(e) { 
alert("This is a test"); 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<ImageView id="image" onClick="doClick" image="images/Checkmark.png" /> 
</Window> 
</Alloy> 
index.js: 
function doClick(e) { 
alert("This is a test"); 
} 
$.index.open();
Adding Content to Views - Creating a Button 
Classic Code: 
app.js 
var button = Ti.UI.createButton({ 
title:'Click Me', 
top: 10, 
width: 100, 
height: 50 
}); 
window.add(button); 
button.addEventListener('click', function(){ 
alert('You clicked me') 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Create the button and establish it's attributes 
var button = Ti.UI.createButton({ 
title:'Click Me', 
top: 10, 
width: 100, 
height: 50 
}); 
//Add the button to the window or view 
window.add(button); 
//Add the function to the button that runs when clicked 
button.addEventListener('click', function(){ 
alert('You clicked me') 
}) 
window.open();
Adding Content to Views - Creating a Button 
Alloy Code: 
index.xml 
<Button id="button" onClick="doClick" title="Click 
Me" /> 
index.js 
function doClick(e) { 
alert("This is a test"); 
} 
index.tss 
"#button":{ 
top: 10, 
width: 100, 
height: 50 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Button id="button" onClick="doClick" title="Hello"/> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#button":{ 
top: 10, 
width: 100, 
height: 50 
} 
index.js: 
function doClick(e) { 
alert("This is a test"); 
} 
$.index.open();
Adding Content to Views - Creating a CUSTOM Button 
Classic Code: 
app.js 
var button = Ti.UI.createButton({ 
title:'Click Me', 
//Establish Up image 
backgroundImage:'images/btn_up.png', 
//Establish Selected image 
backgroundSelectedImage: 'images/btn_down.png', 
top: 10, 
width: 260, 
height: 95 
}); 
window.add(button); 
button.addEventListener('click', function(){ 
alert('You clicked me') 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var button = Ti.UI.createButton({ 
title:'Click Me', 
//Establish Up image 
backgroundImage:'images/btn_up.png', 
//Establish Selected image 
backgroundSelectedImage: 'images/btn_down.png', 
top: 10, 
width: 260, 
height: 95 
}); 
window.add(button); 
button.addEventListener('click', function(){ 
alert('You clicked me') 
}) 
window.open();
Adding Content to Views - Creating a CUSTOM Button 
Alloy Code: 
index.xml 
<Button id="button" onClick="doClick" title="Hello"/> 
index.js 
function doClick(e) { 
alert("Hello"); 
} 
index.tss 
"#button":{ 
backgroundImage: 'images/btn_up.png', 
backgroundSelectedImage: 'images/btn_down.png', 
top: 10, 
width: 260, 
height: 95 
} **NOTE** 
Alloy assets have to be within the assets folder 
//NOTE: Alloy assets have to be within the assets folder 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Button id="button" onClick="doClick" title="Hello"/> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#button":{ 
backgroundImage: 'images/btn_up.png', 
backgroundSelectedImage: 'images/btn_down.png', 
top: 10, 
width: 260, 
height: 95 
} 
index.js: 
function doClick(e) { 
alert("Hello"); 
} 
$.index.open();
Adding Content to Views - Creating a Switch 
Classic Code: 
app.js 
var basicSwitch = Ti.UI.createSwitch({ 
value:true, 
}) 
window.add(basicSwitch); 
basicSwitch.addEventListener('change', function(){ 
alert('Switch Value: ' + basicSwitch.value) 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Create the switch and establish all the attributes for the switch 
var basicSwitch = Ti.UI.createSwitch({ 
value:true, 
}) 
//Add the switch to the window or view 
window.add(basicSwitch); 
//Add an event listener to fire when the switch changes values 
basicSwitch.addEventListener('change', function(){ 
alert('Switch Value: ' + basicSwitch.value) 
}) 
window.open();
Adding Content to Views - Creating a Switch 
Alloy Code: 
index.xml 
<Switch id="basicSwitch" value="true" onChange="outputState"/> 
index.js 
function outputState(e) { 
alert('Switch Value: ' + e.value); 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Switch id="basicSwitch" value="true" onChange="outputState"/> 
</Window> 
</Alloy> 
index.js: 
function outputState(e) { 
alert('Switch Value: ' + e.value); 
}
Adding Content to Views - Creating a Text Field 
Classic Code: 
app.js 
var textField = Ti.UI.createTextField({ 
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
color:’#336699’, 
top: 10, left: 10, 
width: 250, height: 60 
}) 
window.add(textField); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//You first create the text field and add all of it's attributes 
var textField = Ti.UI.createTextField({ 
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
color: '#336699', 
top: 10, left: 10, 
width: 250, height: 60 
}) 
//Add the textfield to the window or the view 
window.add(textField); 
window.open();
Adding Content to Views - Creating a Text Field 
Alloy Code: 
index.xml 
<TextField id="textField" /> 
index.tss 
"#textField": { 
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
color: "#336699", 
top: 10, left: 10, 
width: 250, height: 60 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<TextField id="textField" /> 
</Window> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#textField": { 
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
color: "#336699", 
top: 10, left: 10, 
width: 250, height: 60 
}
Creating Tables 
Classic Code: 
app.js 
var tableData = [ {title:'Apples'}, 
{title: 'Bananas'}, {title: 'Bananas'}, 
{title: 'Potatoes'} ]; 
var table = Ti.UI.createTableView({ 
data: tableData 
}) 
window.add(table); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Establish the data for the table - This is just one possible way 
var tableData = [{title:'Apples'}, {title: 'Bananas'}, {title: 'Bananas'}, {title: 'Potatoes'} ]; 
//Create the table view and assign the data from the table data array 
var table = Ti.UI.createTableView({ 
data: tableData 
}) 
//Adding the table view to the window or view 
window.add(table); 
window.open();
Creating Tables 
Alloy Code: 
index.xml 
<TableView id="table"> 
<TableViewRow title="Apple"/> 
<TableViewRow title="Bananas"/> 
<TableViewRow title="Carrots"/> 
<TableViewRow title="Potatoes"/> 
</TableView> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<TableView id="table"> 
<TableViewRow title="Apple"/> 
<TableViewRow title="Bananas"/> 
<TableViewRow title="Carrots"/> 
<TableViewRow title="Potatoes"/> 
</TableView> 
</Window> 
</Alloy>
Adding Events to Tables 
Classic Code: 
app.js 
table.addEventListener('click', function(e){ 
if(e.index == 0){ 
alert('You clicked 1') 
} else if (e.index == 1){ 
alert('You clicked 2') 
} 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Establish the data for the table - This is just one possible way 
var tableData = [{title:'Apples'}, {title: 'Bananas'}, {title: 'Bananas'}, {title: 'Potatoes'} ]; 
//Create the table view and assign the data from the table data array 
var table = Ti.UI.createTableView({ 
data: tableData 
}) 
//Adding the table view to the window or view 
window.add(table); 
//Adding events to the table 
table.addEventListener('click', function(e){ 
//Check to see which table row was clicked and then you run the code for the table row 
if(e.index == 0){ 
alert('You clicked 1') 
} else if (e.index == 1){ 
alert('You clicked 2') 
} 
}) 
window.open();
Adding Events to Tables 
Alloy Code: 
index.xml 
<TableView id="table" onClick="tableCheck"> 
<TableViewRow title="Apple"/> 
</TableView> 
index.js 
function tableCheck(e) { 
if(e.index == 0){ 
alert('You clicked 1') 
} else if (e.index == 1){ 
alert('You clicked 2') 
} 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<TableView id="table" onClick="tableCheck"> 
<TableViewRow title="Apple"/> 
<TableViewRow title="Bananas"/> 
<TableViewRow title="Carrots"/> 
<TableViewRow title="Potatoes"/> 
<TableViewRow title="Cod"/> 
<TableViewRow title="Haddock"/> 
</TableView> 
</Window> 
</Alloy> 
index.js: 
function tableCheck(e) { 
if(e.index == 0){ 
alert('You clicked 1') 
} else if (e.index == 1){ 
alert('You clicked 2') 
} 
} 
$.index.open();
Creating Tables Sections 
Classic Code: 
app.js 
var sectionFruit = Ti.UI.createTableViewSection({headerTitle: 'Fruit'}); 
sectionFruit.add(Ti.UI.createTableViewRow({title:'Apples'})); 
sectionFruit.add(Ti.UI.createTableViewRow({title:'Bananas'})); 
var sectionVeg = Ti.UI.createTableViewSection({headerTitle: 'Veggies'}); 
sectionVeg.add(Ti.UI.createTableViewRow({title:'Carrots'})); 
sectionVeg.add(Ti.UI.createTableViewRow({title:'Potatoes'})); 
var table = Ti.UI.createTableView({ 
data: [sectionFruit, sectionVeg] 
}) 
window.add(table); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Creating a section for the table. This includes creating a header for the section. 
var sectionFruit = Ti.UI.createTableViewSection({headerTitle: 'Fruit'}); 
//Add rows to this section 
sectionFruit.add(Ti.UI.createTableViewRow({title:'Apples'})); 
sectionFruit.add(Ti.UI.createTableViewRow({title:'Bananas'})); 
//Creating a section for the table. This includes creating a header for the section. 
var sectionVeg = Ti.UI.createTableViewSection({headerTitle: 'Vegetables'}); 
//Add rows to this section 
sectionVeg.add(Ti.UI.createTableViewRow({title:'Carrots'})); 
sectionVeg.add(Ti.UI.createTableViewRow({title:'Potatoes'})); 
//Create the table view and assign the data from the sectionFruit and sectionVeg arrays 
var table = Ti.UI.createTableView({ 
//Assigning both sections to the table 
data: [sectionFruit, sectionVeg] 
}) 
//Adding the table view to the window or view 
window.add(table); 
window.open();
Creating Tables Sections 
Alloy Code: 
index.xml 
<TableView id="table"> 
<TableViewSection id="sectionFruit" headerTitle="Fruit"> 
<TableViewRow title="Apple"/> 
<TableViewRow title="Bananas"/> 
</TableViewSection> 
<TableViewSection id="sectionVeg" 
headerTitle="Vegetables"> 
<TableViewRow title="Carrots"/> 
<TableViewRow title="Potatoes"/> 
</TableViewSection> 
</TableView> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<TableView id="table"> 
<TableViewSection id="sectionFruit" headerTitle="Fruit"> 
<TableViewRow title="Apple"/> 
<TableViewRow title="Bananas"/> 
</TableViewSection> 
<TableViewSection id="sectionVeg" headerTitle="Vegetables"> 
<TableViewRow title="Carrots"/> 
<TableViewRow title="Potatoes"/> 
</TableViewSection> 
<TableViewSection id="sectionFish" headerTitle="Fish"> 
<TableViewRow title="Cod"/> 
<TableViewRow title="Haddock"/> 
</TableViewSection> 
</TableView> 
</Window> 
</Alloy>
Creating Tabs 
Classic Code: 
app.js 
var tabsGroup = Titanium.UI.createTabGroup(); 
//Create the Win1 
var win1 = Titanium.UI.createWindow({ 
backgroundColor:'red' 
}); 
var tab1 = Titanium.UI.createTab({ 
icon: '/images/44-shoebox.png', 
title: 'Reference', 
window: win1 
}); 
var win2 = Titanium.UI.createWindow({ 
backgroundColor:'green' 
}); 
var tab2 = Titanium.UI.createTab({ 
icon: '/images/46-movie-2.png', 
title: 'Sample', 
window: win2 
}); 
tabsGroup.addTab(tab1); 
tabsGroup.addTab(tab2); 
tabsGroup.open(); 
Titanium.UI.setBackgroundColor('#000'); 
var tabGroup = Titanium.UI.createTabGroup(); 
var win1 = Titanium.UI.createWindow({ 
title:'Tab 1', 
backgroundColor:'red' 
}); 
var tab1 = Titanium.UI.createTab({ 
icon:'KS_nav_views.png', 
title:'Tab 1', 
window:win1 
}); 
var win2 = Titanium.UI.createWindow({ 
title:'Tab 2', 
backgroundColor:'green' 
}); 
var tab2 = Titanium.UI.createTab({ 
icon:'KS_nav_ui.png', 
title:'Tab 2', 
window:win2 
}); 
tabGroup.addTab(tab1); 
tabGroup.addTab(tab2); 
tabGroup.open();
Creating Tabs 
Alloy Code: 
index.xml 
<TabGroup> 
<Tab title="Tab 1" icon="KS_nav_ui.png"> 
<Window id="window1" title="Tab 1"> 
<Label>I am Window 1</Label> 
</Window> 
</Tab> 
<Tab title="Tab 2" icon="KS_nav_views.png"> 
<Window id="window2" title="Tab 2"> 
<Label>I am Window 2</Label> 
</Window> 
</Tab> 
</TabGroup> 
index.tss 
"#window1":{ 
backgroundColor:"white" 
}, 
"#window2":{ 
backgroundColor:"white" 
} 
Alloy: 
index.xml: 
<Alloy> 
<TabGroup> 
<Tab title="Tab 1" icon="KS_nav_ui.png"> 
<Window id="window1" title="Tab 1"> 
<Label>I am Window 1</Label> 
</Window> 
</Tab> 
<Tab title="Tab 2" icon="KS_nav_views.png"> 
<Window id="window2" title="Tab 2"> 
<Label>I am Window 2</Label> 
</Window> 
</Tab> 
</TabGroup> 
</Alloy> 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"Label": { 
width: Ti.UI.SIZE, 
height: Ti.UI.SIZE, 
color: "#000" 
}, 
"#window1":{ 
backgroundColor:"white" 
}, 
"#window2":{
Creating a Web View 
Classic Code: 
app.js 
var webView = Ti.UI.createWebView({ 
url:'http://www.kinetic-media.com/jquery' 
}); 
window.add(webView); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Create a webView - The only attribute it needs is the URL but you can add other attributes. 
var webView = Ti.UI.createWebView({ 
url:'http://www.kinetic-media.com/jquery' 
}); 
//Add the webview to the window or view 
window.add(webView); 
window.open();
Creating a Web View 
Alloy Code: 
index.xml 
<WebView id="webview" url="http://www.kinetic-media. 
com/jquery" /> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<WebView id="webview" url="http://www.kinetic-media.com/jquery" /> 
</Window> 
</Alloy>
Creating a Scroll View 
Classic Code: 
app.js 
var scrollView = Ti.UI.createScrollView({ 
contentWidth: '80%', 
contentHeight: 'auto', 
showVerticalScrollIndicator: true, 
showHorizontalScrollIndicator: false, 
height: '80%', 
width: '80%' 
}); 
var view = Ti.UI.createView({ 
backgroundColor:'#336699', 
borderRadius: 10, 
top: 10, 
height: 2000, 
width: 1000 
}); 
scrollView.add(view); 
window.add(scrollView); 
Classic: 
var window = Ti.UI.createWindow({ 
backgroundColor: 'white', 
exitOnClose: true, 
fullscreen: false, 
title: 'ScrollView Demo' 
}); 
var scrollView = Ti.UI.createScrollView({ 
contentWidth: '80%', 
contentHeight: 'auto', 
showVerticalScrollIndicator: true, 
showHorizontalScrollIndicator: false, 
height: '80%', 
width: '80%' 
}); 
var view = Ti.UI.createView({ 
backgroundColor:'#336699', 
borderRadius: 10, 
top: 10, 
height: 2000, 
width: 1000 
}); 
scrollView.add(view); 
window.add(scrollView); 
window.open();
Creating a Scroll View 
Alloy Code: 
index.xml 
<ScrollView id="scrollView" showVerticalScrollIndicator="true" 
showHorizontalScrollIndicator="true" height="80%" width="80%"> 
<View id="view" backgroundColor="#336699" 
borderRadius="10" top="10" height="2000" width="1000" /> 
</ScrollView> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container" backgroundColor="white" exitOnClose="true" 
fullscreen="false" title="ScrollView Demo"> 
<ScrollView id="scrollView" showVerticalScrollIndicator="true" 
showHorizontalScrollIndicator="true" height="80%" width="80%"> 
<View id="view" backgroundColor="#336699" borderRadius="10" top="10" 
height="2000" width="1000" /> 
</ScrollView> 
</Window> 
</Alloy>
Creating a Scrollable View 
Classic Code: 
app.js 
var win = Ti.UI.createWindow(); 
var view1 = 
Ti.UI.createView({ backgroundColor:'#123' }); 
var view2 = 
Ti.UI.createView({ backgroundColor:'#246' }); 
var view3 = 
Ti.UI.createView({ backgroundColor:'#48b' }); 
var scrollableView = Ti.UI.createScrollableView({ 
views:[view1,view2,view3], 
showPagingControl:true 
}); 
win.add(scrollableView); 
win.open(); 
Classic: 
var win = Ti.UI.createWindow({ 
backgroundColor: 'white' 
}); 
var view1 = Ti.UI.createView({ backgroundColor:'#123' }); 
var view2 = Ti.UI.createView({ backgroundColor:'#246' }); 
var view3 = Ti.UI.createView({ backgroundColor:'#48b' }); 
var scrollableView = Ti.UI.createScrollableView({ 
views:[view1,view2,view3], 
showPagingControl:true 
}); 
win.add(scrollableView); 
win.open(); 
or Images 
var img1 = Ti.UI.createImageView({ 
image:'http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/' + 
'Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/' + 
'402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg' 
}); 
var img1Wrapper = Ti.UI.createScrollView({ 
maxZoomScale:4.0, 
}); 
img1Wrapper.add(img1); 
var img2 = Ti.UI.createImageView({
Creating a Scrollable View 
Alloy Code: 
index.xml 
<ScrollableView id="scrollableView" showPagingControl="true"> 
<View id="view1" backgroundColor="#123" /> 
<View id="view2" backgroundColor="#246" /> 
<View id="view3" backgroundColor="#48b" /> 
</ScrollableView> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<ScrollableView id="scrollableView" showPagingControl="true"> 
<View id="view1" backgroundColor="#123" /> 
<View id="view2" backgroundColor="#246" /> 
<View id="view3" backgroundColor="#48b" /> 
</ScrollableView> 
</Window> 
</Alloy>
Playing Sound 
Classic Code: 
app.js 
var player = Ti.Media.createSound({ 
url:'audio/start_race.mp3' 
**NOTE** 
}) 
player.play(); 
Classic assets have to be within a folder 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Create the player element and establish the path to the audio 
var player = Ti.Media.createSound({ 
url:'audio/start_race.mp3' 
}) 
//Play the audio file. This can also be within a function 
player.play(); 
window.open();
Playing Sound 
<Button id="button" onClick="doClick" title="Hello"/> 
var player = Ti.Media.createSound({ 
url:'audio/start_race.mp3' 
**NOTE** 
Alloy Code: 
index.xml 
index.js 
}) 
player.play(); 
Alloy assets have to be within the assets folder 
//NOTE: Alloy assets have to be within the assets folder 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
</Window> 
</Alloy> 
index.js: 
var player = Ti.Media.createSound({ 
url:'audio/start_race.mp3' 
}) 
player.play(); 
$.index.open();
Playing Sound in a Function 
Classic Code: 
app.js 
var buttonSound = Ti.UI.createButton({ 
title: 'Play Sound', 
width: 100, 
height: 50 
}) 
var player = Ti.Media.createSound({ 
url:'audio/Wrong.mp3' 
}) 
window.add(buttonSound); 
buttonSound.addEventListener('click', function(){ 
player.play(); 
}); 
**NOTE** 
Classic assets have to be within the a folder 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var buttonSound = Ti.UI.createButton({ 
title: 'Play Sound', 
width: 100, 
height: 50 
}) 
//Create the player element and establish the path to the audio 
var player = Ti.Media.createSound({ 
url:'audio/Wrong.mp3' 
}) 
window.add(buttonSound); 
//Firing the play audio when the image is tapped 
buttonSound.addEventListener('click', function(){ 
//Play the audio file. This can also be within a function 
player.play(); 
}); 
window.open();
Playing Sound in a Function 
Alloy Code: 
index.xml 
<Button id="button" onClick="doClick" title="Hello"/> 
index.js 
var player = Ti.Media.createSound({ 
url:'audio/Wrong.mp3' 
}) 
function doClick(e) { 
player.play(); 
} 
**NOTE** 
Alloy assets have to be within the assets folder 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Button id="button" onClick="doClick" title="Play Sound"/> 
</Window> 
</Alloy> 
index.js: 
var player = Ti.Media.createSound({ 
url:'audio/Wrong.mp3' 
}) 
function doClick(e) { 
player.play(); 
}
Playing Video 
Classic Code: 
app.js 
var videoPlayer = Ti.Media.createVideoPlayer({ 
url: 'video/Silly_Walks.mp4', 
top: 10, 
autoplay: false, 
height: 230, 
width: 300, 
mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT, 
scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT 
}); 
window.add(videoPlayer); 
**NOTE** 
Classic assets have to be within a folder 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Establish the video player and add all the attributes 
var videoPlayer = Ti.Media.createVideoPlayer({ 
//Video Location 
url: 'video/Silly_Walks.mp4', 
//Video position on the stage 
top: 10, 
//Audtoplay video 
autoplay: false, 
height: 230, 
width: 300, 
//Media controller style 
mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT, 
//Video scaling mode 
scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT 
}); 
//Add the video player to the window or view 
window.add(videoPlayer); 
window.open();
Playing Video 
Alloy Code: 
index.xml 
<VideoPlayer id="videoPlayer" ns="Ti.Media" url="video/ 
Silly_Walks.mp4" autoplay="true" /> 
index.tss 
top:2, 
height:300, 
width:300, 
backgroundColor: 'black' 
**NOTE** 
"#videoPlayer": { 
} 
Alloy assets have to be within the assets folder 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<VideoPlayer id="videoPlayer" ns="Ti.Media" url="video/Silly_Walks.mp4" 
autoplay="true" /> 
</Window> 
</Alloy> 
index.tss: 
"#videoPlayer": { 
top:2, 
height:300, 
width:300, 
backgroundColor: 'black' 
}
Swiping Events 
Classic Code: 
app.js 
window.addEventListener('swipe', function(e){ 
if(e.direction == 'left'){ 
alert('You swiped left') 
} else if (e.direction == 'right'){ 
alert('You swiped right') 
} 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
//Add event listener to the object you want to swipe 
window.addEventListener('swipe', function(e){ 
//If the swipe is left or right 
if(e.direction == 'left'){ 
alert('You swiped left') 
} else if (e.direction == 'right'){ 
alert('You swiped right') 
} 
}) 
window.open();
Swiping Events 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container" onSwipe="swipeEvent"> 
</Window> 
</Alloy> 
index.tss 
function swipeEvent(e){ 
if(e.direction == 'left'){ 
alert('You swiped left') 
} else if (e.direction == 'right'){ 
alert('You swiped right') 
} 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container" onSwipe="swipeEvent"> 
</Window> 
</Alloy> 
index.js: 
function swipeEvent(e){ 
//If the swipe is left or right 
if(e.direction == 'left'){ 
alert('You swiped left') 
} else if (e.direction == 'right'){ 
alert('You swiped right') 
} 
}
Two Finger Tap 
Classic Code: 
app.js 
window.addEventListener('twofingertap', function(e){ 
alert('Two fingers') 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'white' 
}); 
//Add event listener to any object but in this example it is the window. To test in simulator 
hold down the option key. 
window.addEventListener('twofingertap', function(e){ 
alert('Two fingers') 
}) 
window.open();
Two Finger Tap 
Alloy Code: 
index.xml 
<Window class="container" onTwofingertap="twoFingers"> 
</Window> 
index.js 
function twoFingers(){ 
alert("Two fingers"); 
} 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container" onTwofingertap="twoFingers"> 
</Window> 
</Alloy> 
index.js: 
function twoFingers(){ 
alert("Two fingers"); 
}
Shake Events 
Classic Code: 
app.js 
Titanium.Gesture.addEventListener('shake', function(e) 
{ 
alert('Stop shaking me') 
}) 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var label1 = Ti.UI.createLabel({ 
color:'#999', 
text:'Shake the phone', 
font:{fontSize:20, fontfamily:'Helvetica Neue'}, 
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, 
width: Ti.UI.SIZE, height: Ti.UI.SIZE, 
}) 
//You then add your label to the window or view 
window.add(label1) 
Titanium.Gesture.addEventListener('shake', function(e){ 
alert('Stop shaking me') 
}) 
window.open();
Shake Events 
Alloy Code: 
index.js 
Titanium.Gesture.addEventListener('shake', function(e) 
{ 
alert('Stop shaking me') 
}) 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Label id="label">Shake the phone</Label> 
</Window> 
</Alloy> 
index.js: 
Ti.Gesture.addEventListener('shake', function(e){ 
alert('Stop shaking me') 
}); 
$.index.open();
Shake Events 
Classic Code: 
app.js 
Titanium.Gesture.addEventListener('orientationchange', 
function(e){ 
if(e.orientation == 1){ 
alert('You are in PORTRAIT'); 
} else if (e.orientation == 2){ 
alert('You are in UPSIDE_PORTRAIT'); 
} else if (e.orientation == 3){ 
alert('You are in LANDSCAPE_LEFT'); 
} else if (e.orientation == 4){ 
alert('You are in LANDSCAPE_RIGHT'); 
} 
}); 
Titanium.Gesture.addEventListener('orientationchange', function(e){ 
if(e.orientation == 1){ 
alert('You are in PORTRAIT'); 
} else if (e.orientation == 2){ 
alert('You are in UPSIDE_PORTRAIT'); 
} else if (e.orientation == 3){ 
alert('You are in LANDSCAPE_LEFT'); 
} else if (e.orientation == 4){ 
alert('You are in LANDSCAPE_RIGHT'); 
} 
});
Shake Events 
Alloy Code: 
index.js 
Titanium.Gesture.addEventListener('orientationchange', 
function(e){ 
if(e.orientation == 1){ 
alert('You are in PORTRAIT'); 
} else if (e.orientation == 2){ 
alert('You are in UPSIDE_PORTRAIT'); 
} else if (e.orientation == 3){ 
alert('You are in LANDSCAPE_LEFT'); 
} else if (e.orientation == 4){ 
alert('You are in LANDSCAPE_RIGHT'); 
} 
}); 
Titanium.Gesture.addEventListener('orientationchange', function(e){ 
if(e.orientation == 1){ 
alert('You are in PORTRAIT'); 
} else if (e.orientation == 2){ 
alert('You are in UPSIDE_PORTRAIT'); 
} else if (e.orientation == 3){ 
alert('You are in LANDSCAPE_LEFT'); 
} else if (e.orientation == 4){ 
alert('You are in LANDSCAPE_RIGHT'); 
} 
});
Toolbar 
Classic Code: 
app.js 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#336699', 
title:'Main Window' 
}); 
var send = Titanium.UI.createButton({ 
title: 'Send', 
style: Titanium.UI.iPhone.SystemButtonStyle.DONE, 
}); 
var camera = Titanium.UI.createButton({ 
systemButton: Titanium.UI.iPhone.SystemButton.CAMERA, 
}); 
var cancel = Titanium.UI.createButton({ 
systemButton: Titanium.UI.iPhone.SystemButton.CANCEL 
}); 
var flexSpace = Titanium.UI.createButton({ 
systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE 
}); 
var toolbar = Titanium.UI.iOS.createToolbar({ 
items:[send, flexSpace, camera, flexSpace, cancel], 
bottom:0, 
borderTop:true, 
borderBottom:false 
}); 
window.add(toolbar); 
window.open(); 
Classic: 
app.js: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#336699', 
title:'Main Window' 
}); 
var send = Titanium.UI.createButton({ 
title: 'Send', 
style: Titanium.UI.iPhone.SystemButtonStyle.DONE, 
}); 
var camera = Titanium.UI.createButton({ 
systemButton: Titanium.UI.iPhone.SystemButton.CAMERA, 
}); 
var cancel = Titanium.UI.createButton({ 
systemButton: Titanium.UI.iPhone.SystemButton.CANCEL 
}); 
var flexSpace = Titanium.UI.createButton({ 
systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE 
}); 
var toolbar = Titanium.UI.iOS.createToolbar({ 
items:[send, flexSpace, camera, flexSpace, cancel], 
bottom:0, 
borderTop:true, 
borderBottom:false 
});
Toolbar 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container"> 
<Toolbar platform="ios" bottom="0" borderTop="true" 
borderBottom="false" barColor="#000"> 
<!-- The Items tag sets the Toolbar.items property. --> 
<Items> 
<Button id="send" title="Send" 
style="Ti.UI.iPhone.SystemButtonStyle.DONE" /> 
<FlexSpace/> 
<Button id="camera" systemButton="Ti.UI.iPhone.SystemButton.CAMERA" /> 
<FlexSpace/> 
<Button id="cancel" systemButton="Ti.UI.iPhone.SystemButton.CANCEL" /> 
</Items> 
<!-- Place additional views for the Toolbar here. --> 
</Toolbar> 
<Label id="label">I am Window 1</Label> 
</Window> 
</Alloy> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Toolbar platform="ios" bottom="0" borderTop="true" borderBottom="false" barColor="#000"> 
<!-- The Items tag sets the Toolbar.items property. --> 
<Items> 
<Button id="send" title="Send" style="Ti.UI.iPhone.SystemButtonStyle.DONE" /> 
<FlexSpace/> 
<Button id="camera" systemButton="Ti.UI.iPhone.SystemButton.CAMERA" /> 
<FlexSpace/> 
<Button id="cancel" systemButton="Ti.UI.iPhone.SystemButton.CANCEL" /> 
</Items> 
<!-- Place additional views for the Toolbar here. --> 
</Toolbar> 
<Label id="label">I am Window 1</Label> 
</Window> 
</Alloy> 
Or for top 
<Toolbar platform="ios" top="0" borderTop="true" borderBottom="false" barColor="#000">
Tabbed Bar 
Classic Code: 
app.js 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var bb1 = Titanium.UI.iOS.createTabbedBar({ 
labels:['One', 'Two', 'Three'], 
backgroundColor:'#336699', 
top:50, 
style:Titanium.UI.iPhone.SystemButtonStyle.BAR, 
height:25, 
width:200 
}); 
window.add(bb1); 
window.open(); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var bb1 = Titanium.UI.iOS.createTabbedBar({ 
labels:['One', 'Two', 'Three'], 
backgroundColor:'#336699', 
top:50, 
style:Titanium.UI.iPhone.SystemButtonStyle.BAR, 
height:25, 
width:200 
}); 
window.add(bb1); 
window.open();
Tabbed Bar 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container"> 
<TabbedBar id="bb1" platform="ios" backgroundColor="#336699" 
top="50" height="25" width="200" 
style="Titanium.UI.iPhone.SystemButtonStyle.BAR"> 
<Labels> 
<Label> One</Label> 
<Label> Two</Label> 
<Label> Three</Label> 
</Labels> 
</TabbedBar> 
</Window> 
</Alloy> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<TabbedBar id="bb1" platform="ios" backgroundColor="#336699" top="50" height="25" 
width="200" style="Titanium.UI.iPhone.SystemButtonStyle.BAR"> 
<!-- The Labels tag sets the TabbedBar.labels property. --> 
<Labels> 
<!-- Specify text with node text or the title attribute. --> 
<!-- Can also specify the enabled, image and width attributes. --> 
<Label> One</Label> 
<Label> Two</Label> 
<Label> Three</Label> 
</Labels> 
<!-- Place additional views for the TabbedBar here. --> 
</TabbedBar> 
</Window> 
</Alloy>
Picker 
Classic Code: 
app.js 
var picker = Ti.UI.createPicker({ 
top:50 
}); 
var data = []; 
data[0]=Ti.UI.createPickerRow({title:'Bananas'}); 
data[1]=Ti.UI.createPickerRow({title:'Strawberries'}); 
data[2]=Ti.UI.createPickerRow({title:'Mangos'}); 
data[3]=Ti.UI.createPickerRow({title:'Grapes'}); 
picker.add(data); 
picker.selectionIndicator = true; 
win.add(picker); 
win.open(); 
// must be after picker has been displayed 
picker.setSelectedRow(0, 2, false); // select Mangos 
Classic: 
app.js: Single Picker 
Ti.UI.backgroundColor = 'white'; 
var win = Ti.UI.createWindow({ 
exitOnClose: true, 
layout: 'vertical' 
}); 
var picker = Ti.UI.createPicker({ 
top:50 
}); 
var data = []; 
data[0]=Ti.UI.createPickerRow({title:'Bananas'}); 
data[1]=Ti.UI.createPickerRow({title:'Strawberries'}); 
data[2]=Ti.UI.createPickerRow({title:'Mangos'}); 
data[3]=Ti.UI.createPickerRow({title:'Grapes'}); 
picker.add(data); 
picker.selectionIndicator = true; 
win.add(picker); 
win.open(); 
// must be after picker has been displayed 
picker.setSelectedRow(0, 2, false); // select Mangos 
app.js: Multi-Column Picker 
Ti.UI.backgroundColor = 'white'; 
var win = Ti.UI.createWindow({
Toolbar 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container"> 
<Picker id="picker" top="50" selectionIndicator="true" useSpinner="true"> 
<PickerColumn id="column1"> 
<PickerRow title="Bananas"/> 
<PickerRow title="Strawberries"/> 
<PickerRow title="Mangos"/> 
<PickerRow title="Grapes"/> 
</PickerColumn> 
<!-- Picker shorthand notation --> 
<Column id="column2"> 
<Row title="red"/> 
<Row title="green"/> 
<Row title="blue"/> 
<Row title="orange"/> 
</Column> 
</Picker> 
</Window> 
</Alloy> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Picker id="picker" top="50" selectionIndicator="true" useSpinner="true"> 
<PickerColumn id="column1"> 
<PickerRow title="Bananas"/> 
<PickerRow title="Strawberries"/> 
<PickerRow title="Mangos"/> 
<PickerRow title="Grapes"/> 
</PickerColumn> 
<!-- Picker shorthand notation --> 
<Column id="column2"> 
<Row title="red"/> 
<Row title="green"/> 
<Row title="blue"/> 
<Row title="orange"/> 
</Column> 
</Picker> 
</Window> 
</Alloy> 
index.js: 
$.picker.setSelectedRow(0, 2, false); 
$.picker.setSelectedRow(1, 3, false);
Custom Alerts 
Classic Code: 
app.js 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var dialog = Ti.UI.createAlertDialog({ 
message: 'The file has been deleted', 
ok: 'Okay', 
title: 'File Deleted' 
}); 
window.addEventListener('click', function(e){ 
dialog.show(); 
}); 
window.open(); 
Classic: 
Option 1 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
window.addEventListener('click', function(e){ 
alert('The file has been deleted'); 
}); 
window.open(); 
Option 2 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var dialog = Ti.UI.createAlertDialog({ 
message: 'The file has been deleted', 
ok: 'Okay', 
title: 'File Deleted' 
}); 
window.addEventListener('click', function(e){ 
dialog.show(); 
}); 
window.open();
Custom Alerts 
Classic Code: 
app.js 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var dialog = Ti.UI.createAlertDialog({ 
cancel:1, 
buttonNames: ['Confirm', 'Cancel', 'Help'], 
message: 'The file has been deleted', 
title: 'File Deleted' 
}); 
window.addEventListener('click', function(e){ 
dialog.show(); 
}); 
dialog.addEventListener('click', function(e){ 
if(e.index === e.source.cancel){ 
Ti.API.info('The cancel button was clicked'); 
} else if (e.index === 1){ 
Ti.API.info('The help button was clicked'); 
} 
}); 
window.open(); 
Classic: 
Option 3 (Three Buttons): 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#ffffff' 
}); 
var dialog = Ti.UI.createAlertDialog({ 
cancel:1, 
buttonNames: ['Confirm', 'Cancel', 'Help'], 
message: 'The file has been deleted', 
title: 'File Deleted' 
}); 
window.addEventListener('click', function(e){ 
dialog.show(); 
}); 
dialog.addEventListener('click', function(e){ 
if(e.index === e.source.cancel){ 
Ti.API.info('The cancel button was clicked'); 
} else if (e.index === 1){ 
Ti.API.info('The help button was clicked'); 
} 
}); 
window.open();
Opening Up Another Page - Part 1 
Classic Code: 
app.js 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#336699', 
title:'Main Window' 
}); 
//Add button to first window 
var b3 = Titanium.UI.createButton({ 
title:'Open New Win', 
width:200, 
height:40, 
top:110 
}); 
window.add(b3); 
//Event listener to open new window 
b3.addEventListener('click', function() 
{ 
var w = Titanium.UI.createWindow({ 
backgroundColor:'#336699', 
title:'New Window', 
barColor:'black', 
url:'new_window.js' 
}); 
w.open(); 
}); 
window.open(); 
Classic: 
var window = Titanium.UI.createWindow({ 
backgroundColor:'#336699', 
title:'Main Window' 
}); 
//Add button to first window 
var b3 = Titanium.UI.createButton({ 
title:'Open New Win', 
width:200, 
height:40, 
top:110 
}); 
window.add(b3); 
//Event listener to open new window 
b3.addEventListener('click', function() 
{ 
var w = Titanium.UI.createWindow({ 
backgroundColor:'#336699', 
title:'New Window', 
barColor:'black', 
url:'new_window.js' 
}); 
w.open(); 
}); 
window.open();
Opening Up Another Page - Part 2 
Classic Code: 
new_window.js 
var win = Ti.UI.currentWindow; 
var label = Ti.UI.createLabel({ 
color:'#fff', 
text:'test label on new window', 
font:{fontSize:20,fontFamily:'Helvetica Neue'}, 
textAlign:'center', 
width:'auto', 
top: 20 
}); 
label.addEventListener('click', function(){ 
win.close(); 
}) 
win.add(label); 
Classic: 
var win = Ti.UI.currentWindow; 
var label = Ti.UI.createLabel({ 
color:'#fff', 
text:'test label on new window', 
font:{fontSize:20,fontFamily:'Helvetica Neue'}, 
textAlign:'center', 
width:'auto', 
top: 20 
}); 
label.addEventListener('click', function(){ 
win.close(); 
}) 
win.add(label);
Opening Up Another Page - Part 1 XML 
Alloy Code: 
index.xml 
<Alloy> 
<Window class="container"> 
<Label id="label" onClick="showWin1">I'm Window 1</Label> 
</Window> 
</Alloy> 
win2.xml 
<Alloy> 
<Window id="container"> 
<Label id="thelabel" onClick="closeme">I'm Window 2</Label> 
</Window> 
</Alloy> 
Alloy: 
index.xml: 
<Alloy> 
<Window class="container"> 
<Label id="label" onClick="showWin1">I'm Window 1</Label> 
</Window> 
</Alloy> 
win2.xml: 
<Alloy> 
<Window id="container"> 
<Label id="thelabel" onClick="closeme">I'm Window 2</Label> 
</Window> 
</Alloy>
Opening Up Another Page - Part 2 TSS 
Alloy Code: 
index.tss 
".container": { 
backgroundColor:"white" 
}, 
"#Label": { 
width: Ti.UI.SIZE, 
height: Ti.UI.SIZE, 
color: "#000" 
} 
win2.tss 
"#container":{ 
backgroundColor: "#000" 
}, 
"#thelabel":{ 
height: Ti.UI.SIZE, 
width: Ti.UI.SIZE, 
color: "#fff" 
} 
Alloy: 
index.tss: 
".container": { 
backgroundColor:"white" 
}, 
"#Label": { 
width: Ti.UI.SIZE, 
height: Ti.UI.SIZE, 
color: "#000" 
} 
win2.tss: 
"#container":{ 
backgroundColor: "#000" 
}, 
"#thelabel":{ 
height: Ti.UI.SIZE, 
width: Ti.UI.SIZE, 
color: "#fff" 
}
Opening Up Another Page - Part 3 JS 
Alloy Code: 
index.js 
function showWin1(e) { 
var w=Alloy.createController('win2').getView(); 
w.open(); 
} 
$.index.open(); 
win2.js 
function closeme(){ 
$.container.close(); 
}; 
Alloy: 
index.js: 
function showWin1(e) { 
var w=Alloy.createController('win2').getView(); 
w.open(); 
} 
$.index.open(); 
win2.js: 
function closeme(){ 
$.container.close(); 
};

Appcelerator Titanium Kinetic practices part 1

  • 1.
    Jeff Batt eLearningBrothers Appelerator Titanium - Create Mobile Apps Using Javascript, CSS & XML: Product Development Part Manager 1 Jeff Batt Kinetic Media Owner / Head Trainer jeff@kinetic-media.com Contact info: jeff@kinetic-media. com
  • 2.
    www.kinetic-media.com www.youtube.com/jeffbatt01 twitter.com/jeffbatt01 Access Files Connect with me: (www.kinetic-media.com) Approach: • More hands on. Walk you through how to use the software instead of just talking about it. • Hard to tell who is on what level so I start from the beginning on the basic level. • Additional tutorials can be found free on my blog and YouTube channel.
  • 3.
    Differences between Titanium& Phonegap What is the difference between PhoneGap & Titanium? - The basic answer is PhoneGap uses straight HTML so you have to use your own elements in CSS or use some library like jQuery but it does not allow you to use native elements like tabs, table views and other elements.
  • 4.
    Differences between Titanium& Phonegap jQuery Mobile & Phonegap What is the difference between PhoneGap & Titanium? - The basic answer is PhoneGap uses straight HTML so you have to use your own elements in CSS or use some library like jQuery but it does not allow you to use native elements like tabs, table views and other elements.
  • 5.
    Differences between Titanium& Phonegap jQuery Mobile & Phonegap Appcelerator Titanium What is the difference between PhoneGap & Titanium? - The basic answer is PhoneGap uses straight HTML so you have to use your own elements in CSS or use some library like jQuery but it does not allow you to use native elements like tabs, table views and other elements.
  • 6.
    Alloy VS Classic Alloy Classic VS Alloy vs Classic? - Alloy is a new language introduced by Appcelerator. It uses the MVC model. Although both languages can produce the same thing Alloy can do it with less code (most of the times). It also separates your code more for easier maintainability. - It does come down to preference, which way you prefer to code.
  • 7.
    Alloy - MVC index.xml index.tss index.js MVC - Alloy uses uses an MVC model. This separates the code to make it more maintainable. - The model is used in the index.xml to define the content. - The view is used in the index.tss to control the look of the elements. The nice thing about this is you can define different visuals based on device, and OS. - The controller is within the index.js. This controls what happens with elements are clicked on or logic for the app.
  • 8.
    Starting a NewProject Starting a New Project - To start a new project simply click on File > New > Mobile Project
  • 9.
    Starting a NewProject Alloy: Classic: Type of Project - Depending on the type of project you want you can select one of the default templates or just select default to start your own.
  • 10.
    Creating a Window Classic Code: app.js //Establish the window and color var window = Titanium.UI.createWindow({ backgroundColor:'red' }); //Open the window window.open(); Classic: //Establish the window and color var window = Titanium.UI.createWindow({ backgroundColor:'red' }); //Open the window window.open();
  • 11.
    Creating a Window Alloy Code: index.xml <Alloy> <Window class="container"> </Window> </Alloy> index.tss ".container": { backgroundColor:"red" } Alloy: index.xml: <Alloy> <Window class="container"> </Window> </Alloy> index.tss: ".container": { backgroundColor:"red" }
  • 12.
    Windows and Views Windows vs Views - There can only be 1 window open and any time but you can establish a numerous views within the window. You can either add elements to your window or to any view to group them together and then you can position your views form there.
  • 13.
    Windows and Views Window 1 Windows vs Views - There can only be 1 window open and any time but you can establish a numerous views within the window. You can either add elements to your window or to any view to group them together and then you can position your views form there.
  • 14.
    Windows and Views Window 1 View 1 View 2 View 3 Windows vs Views - There can only be 1 window open and any time but you can establish a numerous views within the window. You can either add elements to your window or to any view to group them together and then you can position your views form there.
  • 15.
    Different Types ofViews Window 1 Image View Table View Scroll View Different Types of Views - Like we will learn there are many different types of views you can add or you can have just a normal view.
  • 16.
    Analogy - CreatingObjects then Adding to Window Get the Actor Get the Object var actor = Ti.UI.createView({ }); Compare to Actors on Stage/Camera - Just like getting an actor ready for the stage defining objects to place on the stage is similar. You first define which actor you want to use for your “production”. For the code you choose from the different objects (actors) available and then wrap them in a variable most of the time using the Ti.UI.create... - This isn’t all you need to do. In order for them to be ready you need to define some attributes of how you want them to look/act.
  • 17.
    Analogy - CreatingObjects then Adding to Window Add Attributes to Actor - Makeup - Costume - etc var actor = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); Add Attributes to the Object - Width - Height - etc Compare to Actors on Stage/Camera - Just like an actor cannot just walk off the street and portray the character you have in your mind. You need to define some attributes with them. Such as costume, make up and other things. In this same way you add attributes to your objects such as width, height and others. - This defines what the actor will look like and how they will appear but it still does not place them where they need to be.
  • 18.
    Analogy - CreatingObjects then Adding to Window Add the actor to the stage/ camera Add object to the window or view var actor = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); window.add(actor); image.addEventListener('click', function(){ alert('This is a test'); }) Compare to Actors on Stage/Camera - The final step is to place the actor on stage or on camera. This is where they need to be to be viewed by the audience. If they are not on the camera then your end audience will not see them. - After this is done you then define what the actor should do with the script or in the case of coding javascript or adding event listeners.
  • 19.
    Analogy - CreatingObjects then Adding to Window <Alloy> <Window class="container"> <ImageView id="actor" onClick="doClick" image="images/Checkmark.png" /> </Window> </Alloy> XML - Get the Actor TSS - Define Attributes "#actor":{ top: 10, width: 260, height: 95 function doClick(e) { //Tell the actor what to do } JS - Script what the actor does } Compare to Actors on Stage/Camera - Alloy works the same. You add the object in the XML then add attributes in the TSS file and finally add the script within the JS file.
  • 20.
    Creating a View Classic Code: app.js //Create the view and it's attributes var view1 = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); //Add the view to the window or view window.add(view1); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'white' }); //Create the view and it's attributes var view1 = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); //Add the view to the window or view window.add(view1); window.open();
  • 21.
    Creating a View Alloy Code: index.xml <Alloy> <Window class="container"> <View id="view" /> </Window> </Alloy> index.tss ".container": { backgroundColor:"white" }, "#view": { backgroundColor:"red", width: 50, height: 50, top: 10 } Alloy: index.xml: <Alloy> <Window class="container"> <View id="view" /> </Window> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "#view": { backgroundColor:"red", width: 50, height: 50, top: 10 } or index.xml: <Alloy> <Window class="container"> <View id="view" backgroundColor="red" width="50" height="50" /> </Window> </Alloy>
  • 22.
    Adding Objects toa View Classic Code: app.js //Create the view and it's attributes var view1 = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); //Create the object and its attributes var view2 = Ti.UI.createView({ backgroundColor:'black', width: 20, height: 20, top: 10 }); //Add the second object to the view not the window view1.add(view2); //Add the view to the window or view window.add(view1); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Create the view and it's attributes var view1 = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); //Create the object and its attributes var view2 = Ti.UI.createView({ backgroundColor:'black', width: 20, height: 20, top: 10 }); //Add the second object to the view not the window view1.add(view2); //Add the view to the window or view window.add(view1); window.open();
  • 23.
    Adding Objects toa View Alloy Code: index.xml <View id="view"> <View id="view2"></View> </View> index.tss "#view": { backgroundColor:"red", width: 50, height: 50, top: 10 } "#view2": { backgroundColor:"black", width: 20, height: 20, top: 5 } Alloy: index.xml: <Alloy> <Window class="container"> <View id="view"> <View id="view2"></View> </View> </Window> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "#view": { backgroundColor:"red", width: 50, height: 50, top: 10 } "#view2": { backgroundColor:"black", width: 20, height: 20, top: 5 }
  • 24.
    Adding Content toViews - Creating Labels Classic Code: app.js //This is the code to create a label var label1 = Ti.UI.createLabel({ color:'#999', text:'This is a text', font:{fontSize:20, fontfamily:'Helvetica Neue'}, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, width: Ti.UI.SIZE, height: Ti.UI.SIZE, }) //You then add your label to the window or view window.add(label1) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //This is the code to create a label var label1 = Ti.UI.createLabel({ color:'#999', text:'This is a text', font:{fontSize:20, fontfamily:'Helvetica Neue'}, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, width: Ti.UI.SIZE, height: Ti.UI.SIZE, }) //You then add your label to the window or view window.add(label1) window.open();
  • 25.
    Adding Content toViews - Creating Labels Alloy Code: index.xml <Label id="label1">This is a text</Label> index.tss "#label1": { top: 30, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER } "Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" } Alloy: index.xml: <Alloy> <Window class="container"> <Label id="label1">This is a text</Label> </Window> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "#label1": { top: 30, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER } "Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" }
  • 26.
    Adding Content toViews - Creating Labels Alloy Code (Option 2): index.xml <Label id="label1" color="#900" text="A simple label" textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER" top="30" width="Ti.UI.SIZE" height="Ti.UI.SIZE" /> Alloy (Option 2): index.xml: <Alloy> <Window class="container"> <Label id="label1" color="#900" shadowColor="#aaa" text="A simple label" textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER" top="30" width="Ti.UI.SIZE" height="Ti.UI.SIZE" /> </Window> </Alloy>
  • 27.
    Adding Content toViews - Image View Classic Code: app.js //Create the image and point to the file in a folder var image = Ti.UI.createImageView({ image: 'images/Checkmark.png', //You can also add position or other attributes }) //Add the image to the window or view window.add(image); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Create the image and point to the file in a folder var image = Ti.UI.createImageView({ image: 'images/Checkmark.png', //You can also add position or other attributes }) //Add the image to the window or view window.add(image); window.open();
  • 28.
    Adding Content toViews - Image View Alloy Code: index.xml <ImageView id="image" image="images/Checkmark.png" /> index.tss "#image": { } **NOTE** Alloy assets have to be within the assets folder //NOTE: Alloy assets have to be within the assets folder Alloy: index.xml: <Alloy> <Window class="container"> <ImageView id="image" image="images/Checkmark.png" /> </Window> </Alloy> index.tss: (Optional) "#image": { }
  • 29.
    Adding Event Listeners Classic Code: app.js var image = Ti.UI.createImageView({ image: 'images/Checkmark.png', }) window.add(image); image.addEventListener('click', function(){ alert('This is a test'); }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var image = Ti.UI.createImageView({ image: 'images/Checkmark.png', }) window.add(image); //You can add an event listener to any view, window or object image.addEventListener('click', function(){ alert('This is a test'); }) window.open();
  • 30.
    Adding Event Listeners Alloy Code: index.xml <ImageView id="image" onClick="doClick" image="images/ Checkmark.png" /> index.js function doClick(e) { alert("This is a test"); } Alloy: index.xml: <Alloy> <Window class="container"> <ImageView id="image" onClick="doClick" image="images/Checkmark.png" /> </Window> </Alloy> index.js: function doClick(e) { alert("This is a test"); } $.index.open();
  • 31.
    Adding Content toViews - Creating a Button Classic Code: app.js var button = Ti.UI.createButton({ title:'Click Me', top: 10, width: 100, height: 50 }); window.add(button); button.addEventListener('click', function(){ alert('You clicked me') }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Create the button and establish it's attributes var button = Ti.UI.createButton({ title:'Click Me', top: 10, width: 100, height: 50 }); //Add the button to the window or view window.add(button); //Add the function to the button that runs when clicked button.addEventListener('click', function(){ alert('You clicked me') }) window.open();
  • 32.
    Adding Content toViews - Creating a Button Alloy Code: index.xml <Button id="button" onClick="doClick" title="Click Me" /> index.js function doClick(e) { alert("This is a test"); } index.tss "#button":{ top: 10, width: 100, height: 50 } Alloy: index.xml: <Alloy> <Window class="container"> <Button id="button" onClick="doClick" title="Hello"/> </Window> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "#button":{ top: 10, width: 100, height: 50 } index.js: function doClick(e) { alert("This is a test"); } $.index.open();
  • 33.
    Adding Content toViews - Creating a CUSTOM Button Classic Code: app.js var button = Ti.UI.createButton({ title:'Click Me', //Establish Up image backgroundImage:'images/btn_up.png', //Establish Selected image backgroundSelectedImage: 'images/btn_down.png', top: 10, width: 260, height: 95 }); window.add(button); button.addEventListener('click', function(){ alert('You clicked me') }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var button = Ti.UI.createButton({ title:'Click Me', //Establish Up image backgroundImage:'images/btn_up.png', //Establish Selected image backgroundSelectedImage: 'images/btn_down.png', top: 10, width: 260, height: 95 }); window.add(button); button.addEventListener('click', function(){ alert('You clicked me') }) window.open();
  • 34.
    Adding Content toViews - Creating a CUSTOM Button Alloy Code: index.xml <Button id="button" onClick="doClick" title="Hello"/> index.js function doClick(e) { alert("Hello"); } index.tss "#button":{ backgroundImage: 'images/btn_up.png', backgroundSelectedImage: 'images/btn_down.png', top: 10, width: 260, height: 95 } **NOTE** Alloy assets have to be within the assets folder //NOTE: Alloy assets have to be within the assets folder Alloy: index.xml: <Alloy> <Window class="container"> <Button id="button" onClick="doClick" title="Hello"/> </Window> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "#button":{ backgroundImage: 'images/btn_up.png', backgroundSelectedImage: 'images/btn_down.png', top: 10, width: 260, height: 95 } index.js: function doClick(e) { alert("Hello"); } $.index.open();
  • 35.
    Adding Content toViews - Creating a Switch Classic Code: app.js var basicSwitch = Ti.UI.createSwitch({ value:true, }) window.add(basicSwitch); basicSwitch.addEventListener('change', function(){ alert('Switch Value: ' + basicSwitch.value) }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Create the switch and establish all the attributes for the switch var basicSwitch = Ti.UI.createSwitch({ value:true, }) //Add the switch to the window or view window.add(basicSwitch); //Add an event listener to fire when the switch changes values basicSwitch.addEventListener('change', function(){ alert('Switch Value: ' + basicSwitch.value) }) window.open();
  • 36.
    Adding Content toViews - Creating a Switch Alloy Code: index.xml <Switch id="basicSwitch" value="true" onChange="outputState"/> index.js function outputState(e) { alert('Switch Value: ' + e.value); } Alloy: index.xml: <Alloy> <Window class="container"> <Switch id="basicSwitch" value="true" onChange="outputState"/> </Window> </Alloy> index.js: function outputState(e) { alert('Switch Value: ' + e.value); }
  • 37.
    Adding Content toViews - Creating a Text Field Classic Code: app.js var textField = Ti.UI.createTextField({ borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, color:’#336699’, top: 10, left: 10, width: 250, height: 60 }) window.add(textField); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //You first create the text field and add all of it's attributes var textField = Ti.UI.createTextField({ borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, color: '#336699', top: 10, left: 10, width: 250, height: 60 }) //Add the textfield to the window or the view window.add(textField); window.open();
  • 38.
    Adding Content toViews - Creating a Text Field Alloy Code: index.xml <TextField id="textField" /> index.tss "#textField": { borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, color: "#336699", top: 10, left: 10, width: 250, height: 60 } Alloy: index.xml: <Alloy> <Window class="container"> <TextField id="textField" /> </Window> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "#textField": { borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, color: "#336699", top: 10, left: 10, width: 250, height: 60 }
  • 39.
    Creating Tables ClassicCode: app.js var tableData = [ {title:'Apples'}, {title: 'Bananas'}, {title: 'Bananas'}, {title: 'Potatoes'} ]; var table = Ti.UI.createTableView({ data: tableData }) window.add(table); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Establish the data for the table - This is just one possible way var tableData = [{title:'Apples'}, {title: 'Bananas'}, {title: 'Bananas'}, {title: 'Potatoes'} ]; //Create the table view and assign the data from the table data array var table = Ti.UI.createTableView({ data: tableData }) //Adding the table view to the window or view window.add(table); window.open();
  • 40.
    Creating Tables AlloyCode: index.xml <TableView id="table"> <TableViewRow title="Apple"/> <TableViewRow title="Bananas"/> <TableViewRow title="Carrots"/> <TableViewRow title="Potatoes"/> </TableView> Alloy: index.xml: <Alloy> <Window class="container"> <TableView id="table"> <TableViewRow title="Apple"/> <TableViewRow title="Bananas"/> <TableViewRow title="Carrots"/> <TableViewRow title="Potatoes"/> </TableView> </Window> </Alloy>
  • 41.
    Adding Events toTables Classic Code: app.js table.addEventListener('click', function(e){ if(e.index == 0){ alert('You clicked 1') } else if (e.index == 1){ alert('You clicked 2') } }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Establish the data for the table - This is just one possible way var tableData = [{title:'Apples'}, {title: 'Bananas'}, {title: 'Bananas'}, {title: 'Potatoes'} ]; //Create the table view and assign the data from the table data array var table = Ti.UI.createTableView({ data: tableData }) //Adding the table view to the window or view window.add(table); //Adding events to the table table.addEventListener('click', function(e){ //Check to see which table row was clicked and then you run the code for the table row if(e.index == 0){ alert('You clicked 1') } else if (e.index == 1){ alert('You clicked 2') } }) window.open();
  • 42.
    Adding Events toTables Alloy Code: index.xml <TableView id="table" onClick="tableCheck"> <TableViewRow title="Apple"/> </TableView> index.js function tableCheck(e) { if(e.index == 0){ alert('You clicked 1') } else if (e.index == 1){ alert('You clicked 2') } } Alloy: index.xml: <Alloy> <Window class="container"> <TableView id="table" onClick="tableCheck"> <TableViewRow title="Apple"/> <TableViewRow title="Bananas"/> <TableViewRow title="Carrots"/> <TableViewRow title="Potatoes"/> <TableViewRow title="Cod"/> <TableViewRow title="Haddock"/> </TableView> </Window> </Alloy> index.js: function tableCheck(e) { if(e.index == 0){ alert('You clicked 1') } else if (e.index == 1){ alert('You clicked 2') } } $.index.open();
  • 43.
    Creating Tables Sections Classic Code: app.js var sectionFruit = Ti.UI.createTableViewSection({headerTitle: 'Fruit'}); sectionFruit.add(Ti.UI.createTableViewRow({title:'Apples'})); sectionFruit.add(Ti.UI.createTableViewRow({title:'Bananas'})); var sectionVeg = Ti.UI.createTableViewSection({headerTitle: 'Veggies'}); sectionVeg.add(Ti.UI.createTableViewRow({title:'Carrots'})); sectionVeg.add(Ti.UI.createTableViewRow({title:'Potatoes'})); var table = Ti.UI.createTableView({ data: [sectionFruit, sectionVeg] }) window.add(table); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Creating a section for the table. This includes creating a header for the section. var sectionFruit = Ti.UI.createTableViewSection({headerTitle: 'Fruit'}); //Add rows to this section sectionFruit.add(Ti.UI.createTableViewRow({title:'Apples'})); sectionFruit.add(Ti.UI.createTableViewRow({title:'Bananas'})); //Creating a section for the table. This includes creating a header for the section. var sectionVeg = Ti.UI.createTableViewSection({headerTitle: 'Vegetables'}); //Add rows to this section sectionVeg.add(Ti.UI.createTableViewRow({title:'Carrots'})); sectionVeg.add(Ti.UI.createTableViewRow({title:'Potatoes'})); //Create the table view and assign the data from the sectionFruit and sectionVeg arrays var table = Ti.UI.createTableView({ //Assigning both sections to the table data: [sectionFruit, sectionVeg] }) //Adding the table view to the window or view window.add(table); window.open();
  • 44.
    Creating Tables Sections Alloy Code: index.xml <TableView id="table"> <TableViewSection id="sectionFruit" headerTitle="Fruit"> <TableViewRow title="Apple"/> <TableViewRow title="Bananas"/> </TableViewSection> <TableViewSection id="sectionVeg" headerTitle="Vegetables"> <TableViewRow title="Carrots"/> <TableViewRow title="Potatoes"/> </TableViewSection> </TableView> Alloy: index.xml: <Alloy> <Window class="container"> <TableView id="table"> <TableViewSection id="sectionFruit" headerTitle="Fruit"> <TableViewRow title="Apple"/> <TableViewRow title="Bananas"/> </TableViewSection> <TableViewSection id="sectionVeg" headerTitle="Vegetables"> <TableViewRow title="Carrots"/> <TableViewRow title="Potatoes"/> </TableViewSection> <TableViewSection id="sectionFish" headerTitle="Fish"> <TableViewRow title="Cod"/> <TableViewRow title="Haddock"/> </TableViewSection> </TableView> </Window> </Alloy>
  • 45.
    Creating Tabs ClassicCode: app.js var tabsGroup = Titanium.UI.createTabGroup(); //Create the Win1 var win1 = Titanium.UI.createWindow({ backgroundColor:'red' }); var tab1 = Titanium.UI.createTab({ icon: '/images/44-shoebox.png', title: 'Reference', window: win1 }); var win2 = Titanium.UI.createWindow({ backgroundColor:'green' }); var tab2 = Titanium.UI.createTab({ icon: '/images/46-movie-2.png', title: 'Sample', window: win2 }); tabsGroup.addTab(tab1); tabsGroup.addTab(tab2); tabsGroup.open(); Titanium.UI.setBackgroundColor('#000'); var tabGroup = Titanium.UI.createTabGroup(); var win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'red' }); var tab1 = Titanium.UI.createTab({ icon:'KS_nav_views.png', title:'Tab 1', window:win1 }); var win2 = Titanium.UI.createWindow({ title:'Tab 2', backgroundColor:'green' }); var tab2 = Titanium.UI.createTab({ icon:'KS_nav_ui.png', title:'Tab 2', window:win2 }); tabGroup.addTab(tab1); tabGroup.addTab(tab2); tabGroup.open();
  • 46.
    Creating Tabs AlloyCode: index.xml <TabGroup> <Tab title="Tab 1" icon="KS_nav_ui.png"> <Window id="window1" title="Tab 1"> <Label>I am Window 1</Label> </Window> </Tab> <Tab title="Tab 2" icon="KS_nav_views.png"> <Window id="window2" title="Tab 2"> <Label>I am Window 2</Label> </Window> </Tab> </TabGroup> index.tss "#window1":{ backgroundColor:"white" }, "#window2":{ backgroundColor:"white" } Alloy: index.xml: <Alloy> <TabGroup> <Tab title="Tab 1" icon="KS_nav_ui.png"> <Window id="window1" title="Tab 1"> <Label>I am Window 1</Label> </Window> </Tab> <Tab title="Tab 2" icon="KS_nav_views.png"> <Window id="window2" title="Tab 2"> <Label>I am Window 2</Label> </Window> </Tab> </TabGroup> </Alloy> index.tss: ".container": { backgroundColor:"white" }, "Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" }, "#window1":{ backgroundColor:"white" }, "#window2":{
  • 47.
    Creating a WebView Classic Code: app.js var webView = Ti.UI.createWebView({ url:'http://www.kinetic-media.com/jquery' }); window.add(webView); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Create a webView - The only attribute it needs is the URL but you can add other attributes. var webView = Ti.UI.createWebView({ url:'http://www.kinetic-media.com/jquery' }); //Add the webview to the window or view window.add(webView); window.open();
  • 48.
    Creating a WebView Alloy Code: index.xml <WebView id="webview" url="http://www.kinetic-media. com/jquery" /> Alloy: index.xml: <Alloy> <Window class="container"> <WebView id="webview" url="http://www.kinetic-media.com/jquery" /> </Window> </Alloy>
  • 49.
    Creating a ScrollView Classic Code: app.js var scrollView = Ti.UI.createScrollView({ contentWidth: '80%', contentHeight: 'auto', showVerticalScrollIndicator: true, showHorizontalScrollIndicator: false, height: '80%', width: '80%' }); var view = Ti.UI.createView({ backgroundColor:'#336699', borderRadius: 10, top: 10, height: 2000, width: 1000 }); scrollView.add(view); window.add(scrollView); Classic: var window = Ti.UI.createWindow({ backgroundColor: 'white', exitOnClose: true, fullscreen: false, title: 'ScrollView Demo' }); var scrollView = Ti.UI.createScrollView({ contentWidth: '80%', contentHeight: 'auto', showVerticalScrollIndicator: true, showHorizontalScrollIndicator: false, height: '80%', width: '80%' }); var view = Ti.UI.createView({ backgroundColor:'#336699', borderRadius: 10, top: 10, height: 2000, width: 1000 }); scrollView.add(view); window.add(scrollView); window.open();
  • 50.
    Creating a ScrollView Alloy Code: index.xml <ScrollView id="scrollView" showVerticalScrollIndicator="true" showHorizontalScrollIndicator="true" height="80%" width="80%"> <View id="view" backgroundColor="#336699" borderRadius="10" top="10" height="2000" width="1000" /> </ScrollView> Alloy: index.xml: <Alloy> <Window class="container" backgroundColor="white" exitOnClose="true" fullscreen="false" title="ScrollView Demo"> <ScrollView id="scrollView" showVerticalScrollIndicator="true" showHorizontalScrollIndicator="true" height="80%" width="80%"> <View id="view" backgroundColor="#336699" borderRadius="10" top="10" height="2000" width="1000" /> </ScrollView> </Window> </Alloy>
  • 51.
    Creating a ScrollableView Classic Code: app.js var win = Ti.UI.createWindow(); var view1 = Ti.UI.createView({ backgroundColor:'#123' }); var view2 = Ti.UI.createView({ backgroundColor:'#246' }); var view3 = Ti.UI.createView({ backgroundColor:'#48b' }); var scrollableView = Ti.UI.createScrollableView({ views:[view1,view2,view3], showPagingControl:true }); win.add(scrollableView); win.open(); Classic: var win = Ti.UI.createWindow({ backgroundColor: 'white' }); var view1 = Ti.UI.createView({ backgroundColor:'#123' }); var view2 = Ti.UI.createView({ backgroundColor:'#246' }); var view3 = Ti.UI.createView({ backgroundColor:'#48b' }); var scrollableView = Ti.UI.createScrollableView({ views:[view1,view2,view3], showPagingControl:true }); win.add(scrollableView); win.open(); or Images var img1 = Ti.UI.createImageView({ image:'http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/' + 'Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/' + '402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg' }); var img1Wrapper = Ti.UI.createScrollView({ maxZoomScale:4.0, }); img1Wrapper.add(img1); var img2 = Ti.UI.createImageView({
  • 52.
    Creating a ScrollableView Alloy Code: index.xml <ScrollableView id="scrollableView" showPagingControl="true"> <View id="view1" backgroundColor="#123" /> <View id="view2" backgroundColor="#246" /> <View id="view3" backgroundColor="#48b" /> </ScrollableView> Alloy: index.xml: <Alloy> <Window class="container"> <ScrollableView id="scrollableView" showPagingControl="true"> <View id="view1" backgroundColor="#123" /> <View id="view2" backgroundColor="#246" /> <View id="view3" backgroundColor="#48b" /> </ScrollableView> </Window> </Alloy>
  • 53.
    Playing Sound ClassicCode: app.js var player = Ti.Media.createSound({ url:'audio/start_race.mp3' **NOTE** }) player.play(); Classic assets have to be within a folder Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Create the player element and establish the path to the audio var player = Ti.Media.createSound({ url:'audio/start_race.mp3' }) //Play the audio file. This can also be within a function player.play(); window.open();
  • 54.
    Playing Sound <Buttonid="button" onClick="doClick" title="Hello"/> var player = Ti.Media.createSound({ url:'audio/start_race.mp3' **NOTE** Alloy Code: index.xml index.js }) player.play(); Alloy assets have to be within the assets folder //NOTE: Alloy assets have to be within the assets folder Alloy: index.xml: <Alloy> <Window class="container"> </Window> </Alloy> index.js: var player = Ti.Media.createSound({ url:'audio/start_race.mp3' }) player.play(); $.index.open();
  • 55.
    Playing Sound ina Function Classic Code: app.js var buttonSound = Ti.UI.createButton({ title: 'Play Sound', width: 100, height: 50 }) var player = Ti.Media.createSound({ url:'audio/Wrong.mp3' }) window.add(buttonSound); buttonSound.addEventListener('click', function(){ player.play(); }); **NOTE** Classic assets have to be within the a folder Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var buttonSound = Ti.UI.createButton({ title: 'Play Sound', width: 100, height: 50 }) //Create the player element and establish the path to the audio var player = Ti.Media.createSound({ url:'audio/Wrong.mp3' }) window.add(buttonSound); //Firing the play audio when the image is tapped buttonSound.addEventListener('click', function(){ //Play the audio file. This can also be within a function player.play(); }); window.open();
  • 56.
    Playing Sound ina Function Alloy Code: index.xml <Button id="button" onClick="doClick" title="Hello"/> index.js var player = Ti.Media.createSound({ url:'audio/Wrong.mp3' }) function doClick(e) { player.play(); } **NOTE** Alloy assets have to be within the assets folder Alloy: index.xml: <Alloy> <Window class="container"> <Button id="button" onClick="doClick" title="Play Sound"/> </Window> </Alloy> index.js: var player = Ti.Media.createSound({ url:'audio/Wrong.mp3' }) function doClick(e) { player.play(); }
  • 57.
    Playing Video ClassicCode: app.js var videoPlayer = Ti.Media.createVideoPlayer({ url: 'video/Silly_Walks.mp4', top: 10, autoplay: false, height: 230, width: 300, mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT, scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT }); window.add(videoPlayer); **NOTE** Classic assets have to be within a folder Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Establish the video player and add all the attributes var videoPlayer = Ti.Media.createVideoPlayer({ //Video Location url: 'video/Silly_Walks.mp4', //Video position on the stage top: 10, //Audtoplay video autoplay: false, height: 230, width: 300, //Media controller style mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT, //Video scaling mode scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT }); //Add the video player to the window or view window.add(videoPlayer); window.open();
  • 58.
    Playing Video AlloyCode: index.xml <VideoPlayer id="videoPlayer" ns="Ti.Media" url="video/ Silly_Walks.mp4" autoplay="true" /> index.tss top:2, height:300, width:300, backgroundColor: 'black' **NOTE** "#videoPlayer": { } Alloy assets have to be within the assets folder Alloy: index.xml: <Alloy> <Window class="container"> <VideoPlayer id="videoPlayer" ns="Ti.Media" url="video/Silly_Walks.mp4" autoplay="true" /> </Window> </Alloy> index.tss: "#videoPlayer": { top:2, height:300, width:300, backgroundColor: 'black' }
  • 59.
    Swiping Events ClassicCode: app.js window.addEventListener('swipe', function(e){ if(e.direction == 'left'){ alert('You swiped left') } else if (e.direction == 'right'){ alert('You swiped right') } }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); //Add event listener to the object you want to swipe window.addEventListener('swipe', function(e){ //If the swipe is left or right if(e.direction == 'left'){ alert('You swiped left') } else if (e.direction == 'right'){ alert('You swiped right') } }) window.open();
  • 60.
    Swiping Events AlloyCode: index.xml <Alloy> <Window class="container" onSwipe="swipeEvent"> </Window> </Alloy> index.tss function swipeEvent(e){ if(e.direction == 'left'){ alert('You swiped left') } else if (e.direction == 'right'){ alert('You swiped right') } } Alloy: index.xml: <Alloy> <Window class="container" onSwipe="swipeEvent"> </Window> </Alloy> index.js: function swipeEvent(e){ //If the swipe is left or right if(e.direction == 'left'){ alert('You swiped left') } else if (e.direction == 'right'){ alert('You swiped right') } }
  • 61.
    Two Finger Tap Classic Code: app.js window.addEventListener('twofingertap', function(e){ alert('Two fingers') }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'white' }); //Add event listener to any object but in this example it is the window. To test in simulator hold down the option key. window.addEventListener('twofingertap', function(e){ alert('Two fingers') }) window.open();
  • 62.
    Two Finger Tap Alloy Code: index.xml <Window class="container" onTwofingertap="twoFingers"> </Window> index.js function twoFingers(){ alert("Two fingers"); } Alloy: index.xml: <Alloy> <Window class="container" onTwofingertap="twoFingers"> </Window> </Alloy> index.js: function twoFingers(){ alert("Two fingers"); }
  • 63.
    Shake Events ClassicCode: app.js Titanium.Gesture.addEventListener('shake', function(e) { alert('Stop shaking me') }) Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var label1 = Ti.UI.createLabel({ color:'#999', text:'Shake the phone', font:{fontSize:20, fontfamily:'Helvetica Neue'}, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, width: Ti.UI.SIZE, height: Ti.UI.SIZE, }) //You then add your label to the window or view window.add(label1) Titanium.Gesture.addEventListener('shake', function(e){ alert('Stop shaking me') }) window.open();
  • 64.
    Shake Events AlloyCode: index.js Titanium.Gesture.addEventListener('shake', function(e) { alert('Stop shaking me') }) Alloy: index.xml: <Alloy> <Window class="container"> <Label id="label">Shake the phone</Label> </Window> </Alloy> index.js: Ti.Gesture.addEventListener('shake', function(e){ alert('Stop shaking me') }); $.index.open();
  • 65.
    Shake Events ClassicCode: app.js Titanium.Gesture.addEventListener('orientationchange', function(e){ if(e.orientation == 1){ alert('You are in PORTRAIT'); } else if (e.orientation == 2){ alert('You are in UPSIDE_PORTRAIT'); } else if (e.orientation == 3){ alert('You are in LANDSCAPE_LEFT'); } else if (e.orientation == 4){ alert('You are in LANDSCAPE_RIGHT'); } }); Titanium.Gesture.addEventListener('orientationchange', function(e){ if(e.orientation == 1){ alert('You are in PORTRAIT'); } else if (e.orientation == 2){ alert('You are in UPSIDE_PORTRAIT'); } else if (e.orientation == 3){ alert('You are in LANDSCAPE_LEFT'); } else if (e.orientation == 4){ alert('You are in LANDSCAPE_RIGHT'); } });
  • 66.
    Shake Events AlloyCode: index.js Titanium.Gesture.addEventListener('orientationchange', function(e){ if(e.orientation == 1){ alert('You are in PORTRAIT'); } else if (e.orientation == 2){ alert('You are in UPSIDE_PORTRAIT'); } else if (e.orientation == 3){ alert('You are in LANDSCAPE_LEFT'); } else if (e.orientation == 4){ alert('You are in LANDSCAPE_RIGHT'); } }); Titanium.Gesture.addEventListener('orientationchange', function(e){ if(e.orientation == 1){ alert('You are in PORTRAIT'); } else if (e.orientation == 2){ alert('You are in UPSIDE_PORTRAIT'); } else if (e.orientation == 3){ alert('You are in LANDSCAPE_LEFT'); } else if (e.orientation == 4){ alert('You are in LANDSCAPE_RIGHT'); } });
  • 67.
    Toolbar Classic Code: app.js var window = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'Main Window' }); var send = Titanium.UI.createButton({ title: 'Send', style: Titanium.UI.iPhone.SystemButtonStyle.DONE, }); var camera = Titanium.UI.createButton({ systemButton: Titanium.UI.iPhone.SystemButton.CAMERA, }); var cancel = Titanium.UI.createButton({ systemButton: Titanium.UI.iPhone.SystemButton.CANCEL }); var flexSpace = Titanium.UI.createButton({ systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE }); var toolbar = Titanium.UI.iOS.createToolbar({ items:[send, flexSpace, camera, flexSpace, cancel], bottom:0, borderTop:true, borderBottom:false }); window.add(toolbar); window.open(); Classic: app.js: var window = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'Main Window' }); var send = Titanium.UI.createButton({ title: 'Send', style: Titanium.UI.iPhone.SystemButtonStyle.DONE, }); var camera = Titanium.UI.createButton({ systemButton: Titanium.UI.iPhone.SystemButton.CAMERA, }); var cancel = Titanium.UI.createButton({ systemButton: Titanium.UI.iPhone.SystemButton.CANCEL }); var flexSpace = Titanium.UI.createButton({ systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE }); var toolbar = Titanium.UI.iOS.createToolbar({ items:[send, flexSpace, camera, flexSpace, cancel], bottom:0, borderTop:true, borderBottom:false });
  • 68.
    Toolbar Alloy Code: index.xml <Alloy> <Window class="container"> <Toolbar platform="ios" bottom="0" borderTop="true" borderBottom="false" barColor="#000"> <!-- The Items tag sets the Toolbar.items property. --> <Items> <Button id="send" title="Send" style="Ti.UI.iPhone.SystemButtonStyle.DONE" /> <FlexSpace/> <Button id="camera" systemButton="Ti.UI.iPhone.SystemButton.CAMERA" /> <FlexSpace/> <Button id="cancel" systemButton="Ti.UI.iPhone.SystemButton.CANCEL" /> </Items> <!-- Place additional views for the Toolbar here. --> </Toolbar> <Label id="label">I am Window 1</Label> </Window> </Alloy> Alloy: index.xml: <Alloy> <Window class="container"> <Toolbar platform="ios" bottom="0" borderTop="true" borderBottom="false" barColor="#000"> <!-- The Items tag sets the Toolbar.items property. --> <Items> <Button id="send" title="Send" style="Ti.UI.iPhone.SystemButtonStyle.DONE" /> <FlexSpace/> <Button id="camera" systemButton="Ti.UI.iPhone.SystemButton.CAMERA" /> <FlexSpace/> <Button id="cancel" systemButton="Ti.UI.iPhone.SystemButton.CANCEL" /> </Items> <!-- Place additional views for the Toolbar here. --> </Toolbar> <Label id="label">I am Window 1</Label> </Window> </Alloy> Or for top <Toolbar platform="ios" top="0" borderTop="true" borderBottom="false" barColor="#000">
  • 69.
    Tabbed Bar ClassicCode: app.js var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var bb1 = Titanium.UI.iOS.createTabbedBar({ labels:['One', 'Two', 'Three'], backgroundColor:'#336699', top:50, style:Titanium.UI.iPhone.SystemButtonStyle.BAR, height:25, width:200 }); window.add(bb1); window.open(); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var bb1 = Titanium.UI.iOS.createTabbedBar({ labels:['One', 'Two', 'Three'], backgroundColor:'#336699', top:50, style:Titanium.UI.iPhone.SystemButtonStyle.BAR, height:25, width:200 }); window.add(bb1); window.open();
  • 70.
    Tabbed Bar AlloyCode: index.xml <Alloy> <Window class="container"> <TabbedBar id="bb1" platform="ios" backgroundColor="#336699" top="50" height="25" width="200" style="Titanium.UI.iPhone.SystemButtonStyle.BAR"> <Labels> <Label> One</Label> <Label> Two</Label> <Label> Three</Label> </Labels> </TabbedBar> </Window> </Alloy> Alloy: index.xml: <Alloy> <Window class="container"> <TabbedBar id="bb1" platform="ios" backgroundColor="#336699" top="50" height="25" width="200" style="Titanium.UI.iPhone.SystemButtonStyle.BAR"> <!-- The Labels tag sets the TabbedBar.labels property. --> <Labels> <!-- Specify text with node text or the title attribute. --> <!-- Can also specify the enabled, image and width attributes. --> <Label> One</Label> <Label> Two</Label> <Label> Three</Label> </Labels> <!-- Place additional views for the TabbedBar here. --> </TabbedBar> </Window> </Alloy>
  • 71.
    Picker Classic Code: app.js var picker = Ti.UI.createPicker({ top:50 }); var data = []; data[0]=Ti.UI.createPickerRow({title:'Bananas'}); data[1]=Ti.UI.createPickerRow({title:'Strawberries'}); data[2]=Ti.UI.createPickerRow({title:'Mangos'}); data[3]=Ti.UI.createPickerRow({title:'Grapes'}); picker.add(data); picker.selectionIndicator = true; win.add(picker); win.open(); // must be after picker has been displayed picker.setSelectedRow(0, 2, false); // select Mangos Classic: app.js: Single Picker Ti.UI.backgroundColor = 'white'; var win = Ti.UI.createWindow({ exitOnClose: true, layout: 'vertical' }); var picker = Ti.UI.createPicker({ top:50 }); var data = []; data[0]=Ti.UI.createPickerRow({title:'Bananas'}); data[1]=Ti.UI.createPickerRow({title:'Strawberries'}); data[2]=Ti.UI.createPickerRow({title:'Mangos'}); data[3]=Ti.UI.createPickerRow({title:'Grapes'}); picker.add(data); picker.selectionIndicator = true; win.add(picker); win.open(); // must be after picker has been displayed picker.setSelectedRow(0, 2, false); // select Mangos app.js: Multi-Column Picker Ti.UI.backgroundColor = 'white'; var win = Ti.UI.createWindow({
  • 72.
    Toolbar Alloy Code: index.xml <Alloy> <Window class="container"> <Picker id="picker" top="50" selectionIndicator="true" useSpinner="true"> <PickerColumn id="column1"> <PickerRow title="Bananas"/> <PickerRow title="Strawberries"/> <PickerRow title="Mangos"/> <PickerRow title="Grapes"/> </PickerColumn> <!-- Picker shorthand notation --> <Column id="column2"> <Row title="red"/> <Row title="green"/> <Row title="blue"/> <Row title="orange"/> </Column> </Picker> </Window> </Alloy> Alloy: index.xml: <Alloy> <Window class="container"> <Picker id="picker" top="50" selectionIndicator="true" useSpinner="true"> <PickerColumn id="column1"> <PickerRow title="Bananas"/> <PickerRow title="Strawberries"/> <PickerRow title="Mangos"/> <PickerRow title="Grapes"/> </PickerColumn> <!-- Picker shorthand notation --> <Column id="column2"> <Row title="red"/> <Row title="green"/> <Row title="blue"/> <Row title="orange"/> </Column> </Picker> </Window> </Alloy> index.js: $.picker.setSelectedRow(0, 2, false); $.picker.setSelectedRow(1, 3, false);
  • 73.
    Custom Alerts ClassicCode: app.js var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var dialog = Ti.UI.createAlertDialog({ message: 'The file has been deleted', ok: 'Okay', title: 'File Deleted' }); window.addEventListener('click', function(e){ dialog.show(); }); window.open(); Classic: Option 1 var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); window.addEventListener('click', function(e){ alert('The file has been deleted'); }); window.open(); Option 2 var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var dialog = Ti.UI.createAlertDialog({ message: 'The file has been deleted', ok: 'Okay', title: 'File Deleted' }); window.addEventListener('click', function(e){ dialog.show(); }); window.open();
  • 74.
    Custom Alerts ClassicCode: app.js var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var dialog = Ti.UI.createAlertDialog({ cancel:1, buttonNames: ['Confirm', 'Cancel', 'Help'], message: 'The file has been deleted', title: 'File Deleted' }); window.addEventListener('click', function(e){ dialog.show(); }); dialog.addEventListener('click', function(e){ if(e.index === e.source.cancel){ Ti.API.info('The cancel button was clicked'); } else if (e.index === 1){ Ti.API.info('The help button was clicked'); } }); window.open(); Classic: Option 3 (Three Buttons): var window = Titanium.UI.createWindow({ backgroundColor:'#ffffff' }); var dialog = Ti.UI.createAlertDialog({ cancel:1, buttonNames: ['Confirm', 'Cancel', 'Help'], message: 'The file has been deleted', title: 'File Deleted' }); window.addEventListener('click', function(e){ dialog.show(); }); dialog.addEventListener('click', function(e){ if(e.index === e.source.cancel){ Ti.API.info('The cancel button was clicked'); } else if (e.index === 1){ Ti.API.info('The help button was clicked'); } }); window.open();
  • 75.
    Opening Up AnotherPage - Part 1 Classic Code: app.js var window = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'Main Window' }); //Add button to first window var b3 = Titanium.UI.createButton({ title:'Open New Win', width:200, height:40, top:110 }); window.add(b3); //Event listener to open new window b3.addEventListener('click', function() { var w = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'New Window', barColor:'black', url:'new_window.js' }); w.open(); }); window.open(); Classic: var window = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'Main Window' }); //Add button to first window var b3 = Titanium.UI.createButton({ title:'Open New Win', width:200, height:40, top:110 }); window.add(b3); //Event listener to open new window b3.addEventListener('click', function() { var w = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'New Window', barColor:'black', url:'new_window.js' }); w.open(); }); window.open();
  • 76.
    Opening Up AnotherPage - Part 2 Classic Code: new_window.js var win = Ti.UI.currentWindow; var label = Ti.UI.createLabel({ color:'#fff', text:'test label on new window', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto', top: 20 }); label.addEventListener('click', function(){ win.close(); }) win.add(label); Classic: var win = Ti.UI.currentWindow; var label = Ti.UI.createLabel({ color:'#fff', text:'test label on new window', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto', top: 20 }); label.addEventListener('click', function(){ win.close(); }) win.add(label);
  • 77.
    Opening Up AnotherPage - Part 1 XML Alloy Code: index.xml <Alloy> <Window class="container"> <Label id="label" onClick="showWin1">I'm Window 1</Label> </Window> </Alloy> win2.xml <Alloy> <Window id="container"> <Label id="thelabel" onClick="closeme">I'm Window 2</Label> </Window> </Alloy> Alloy: index.xml: <Alloy> <Window class="container"> <Label id="label" onClick="showWin1">I'm Window 1</Label> </Window> </Alloy> win2.xml: <Alloy> <Window id="container"> <Label id="thelabel" onClick="closeme">I'm Window 2</Label> </Window> </Alloy>
  • 78.
    Opening Up AnotherPage - Part 2 TSS Alloy Code: index.tss ".container": { backgroundColor:"white" }, "#Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" } win2.tss "#container":{ backgroundColor: "#000" }, "#thelabel":{ height: Ti.UI.SIZE, width: Ti.UI.SIZE, color: "#fff" } Alloy: index.tss: ".container": { backgroundColor:"white" }, "#Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" } win2.tss: "#container":{ backgroundColor: "#000" }, "#thelabel":{ height: Ti.UI.SIZE, width: Ti.UI.SIZE, color: "#fff" }
  • 79.
    Opening Up AnotherPage - Part 3 JS Alloy Code: index.js function showWin1(e) { var w=Alloy.createController('win2').getView(); w.open(); } $.index.open(); win2.js function closeme(){ $.container.close(); }; Alloy: index.js: function showWin1(e) { var w=Alloy.createController('win2').getView(); w.open(); } $.index.open(); win2.js: function closeme(){ $.container.close(); };