Skip to content

Instantly share code, notes, and snippets.

View jonalter's full-sized avatar

Jonathan Alter jonalter

View GitHub Profile
@jonalter
jonalter / app.js
Created April 11, 2012 20:24
iOS: using a tableView to scroll horizontally like pulse
var colors = ['red', 'green', 'blue', 'pink', 'brown'];
var data = [];
var win = Ti.UI.createWindow({
backgroundColor: 'white'
});
win.open();
function createRow(params){
var row = Ti.UI.createTableViewRow({
@jonalter
jonalter / app.js
Created March 6, 2012 20:57
iOS/Android: permanently caching imageView
App.UI.Image = function(_params) {
_params.preventDefaultImage = true;
var folder = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "cache");
if(!folder.exists()){
folder.createDirectory();
}
var filename = Ti.Utils.base64encode(_params.image.toString());
@jonalter
jonalter / app.js
Created February 10, 2012 16:26
iOS: convert view layout to single image using toImage()
var win = Ti.UI.createWindow({backgroundColor:'white'});
win.open();
// build our layout with 2 views and 1 imageView
var mainView = Ti.UI.createView({top:10,height:200,width:200,backgroundColor:'blue'});
var view2 = Ti.UI.createView({height:100,width:100,backgroundColor:'green'});
var imageView = Ti.UI.createImageView({image:'http://www.appcelerator.com/wp-content/uploads/2011/01/Appcelerator-IDC-Q1-Mobile-Developer-Report-appclogo.png'});
mainView.add(view2);
view2.add(imageView);
@jonalter
jonalter / app.js
Created February 6, 2012 23:19
iOS: fake loading screen for barcode module
var Barcode = require('ti.barcode');
Barcode.allowRotation = false;
var barLoadWin = null;
 
Barcode.addEventListener('error', function(e) {
    Ti.API.info('ERROR called with barcode: ' + e);
    if(barLoadWin){
        barLoadWin.close();
    }
});
@jonalter
jonalter / app.js
Created January 16, 2012 18:32
Resize image in imageView
function squareImage(imageView){
function getThumb(){
imageView.removeEventListener('load',getThumb);
var blob = imageView.toBlob();
var height = blob.height;
var width = blob.width;
if(height < width){
var size = height;
@jonalter
jonalter / app.js
Created January 6, 2012 23:34
Update TableViewRows in place
var win = Ti.UI.createWindow({
backgroundColor : '#fff'
});
var rows = [];
function createRow(){
var row1 = Ti.UI.createTableViewRow();
var label = Ti.UI.createLabel({
text: 'heyyyyyy',
@jonalter
jonalter / app.js
Created December 21, 2011 04:29
iOS: custom TabbedBar
var win = Ti.UI.createWindow();
var view = Ti.UI.createView({
top:0,
left:0,
backgroundImage:'bluebar.png',
height:44,
width:320
});
@jonalter
jonalter / app.js
Created December 20, 2011 21:39
iOS: drag and drop using convertPointToView
var win = Ti.UI.createWindow({
masterWindow: true,
backgroundColor: 'white'
});
var view1 = Ti.UI.createView({
top : 20,
left : 20,
height : 100,
width : 100,
@jonalter
jonalter / app.js
Created December 6, 2011 21:38
Remove all children function
// Remove all children from a view
// Pedro :)
function removeChildren(el){
var children = el.children;
while(el.children.length){
var child = children[el.children.length-1];
removeChildren(child);
el.remove(child);
}
@jonalter
jonalter / info.plist
Created November 22, 2011 02:24
iOS: launch your app from another app
// info.plist from Test 5
// Open your info.plist and look for CFBundleURLSchemes
// this is the string that you will use to open that app
// You can also copy the info.plist to the root of your app and edit it.
// You can even have multiple schemes that you can use to launch it.
// Here I can launch the app using either 'test5://' or 'pedro://'
// Be SURE to do a clean build
<key>CFBundleURLSchemes</key>
<array>