Thursday, May 15, 2014

Titanium Appcelerator - commonly used API & quick code samples

 http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Label
var label2 = Ti.UI.createLabel({
  color:'blue',
  text: 'A long label with\na few line breaks\nand unicode (UTF8)\nsymbols such as\na white chess piece \u2655\nand the euro symbol \u20ac\nlooks like this!\n',
  textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
  top: 30,
  width: 300, height: 200
});

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Button
var button = Titanium.UI.createButton({
   title: 'Hello',
   top: 10,
   width: 100,
   height: 50
});
button.addEventListener('click',function(e)
{
   Titanium.API.info("You clicked the button");
});

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TextField
var textField = Ti.UI.createTextField({
  borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
  color: '#336699',
  top: 10, left: 10,
  width: 250, height: 60
});

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.View
var view = Titanium.UI.createView({
   borderRadius:10,
   backgroundColor:'red',
   width:50,
   height:50
});

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.ScrollView
var scrollView = Ti.UI.createScrollView({
  contentWidth: 'auto',
  contentHeight: 'auto',
  showVerticalScrollIndicator: true,
  showHorizontalScrollIndicator: true,
  height: '80%',
  width: '80%'
});

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TableView
var tableData = [ {title: 'Apples'}, {title: 'Bananas'}, {title: 'Carrots'}, {title: 'Potatoes'} ];
var table = Ti.UI.createTableView({
  data: tableData
});

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Window
var window = Titanium.UI.createWindow({
     backgroundColor:"#FFC",
     title:"Scroll View Demo",
     navBarHidden:true,
    url:"ScrollViewDemo.js"
 });
 window.open();

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.ImageView
var image = Ti.UI.createImageView({
  image:'/images/banner.jpg'     // assuming that the JPG is stored in 'images' folder in 'Resources' folder
});

http://developer.appcelerator.com/question/116655/session---global-variables
eg.: Ti.App.myVar (something like session variable)
OR
Ti.App.Properties.setObject("mystr", "mystr") // persistant storage
OR
newWindow.myVar (something like GET variable passed)

No comments: