Skip to content

Instantly share code, notes, and snippets.

@kosso
Last active December 23, 2015 04:59
Show Gist options
  • Save kosso/6583973 to your computer and use it in GitHub Desktop.
Save kosso/6583973 to your computer and use it in GitHub Desktop.
Fun with Ti.UI.iOS.NavigationWindow !
/*
Fun with NavigationWindow!
creates random coloured windows which create buttons which create random coloured windows which create buttons which...
you get the picture ;)
Required : Titanium SDK 3.1.3 or higher.
Kosso
*/
function randomColor(){
return '#'+(function lol(m,s,c){return s[m.floor(m.random() * s.length)] + (c && lol(m,s,c-1));})(Math,'0123456789ABCDEF',4);
}
// Works with Release 3.1.3 and later
var rootWin = Ti.UI.createWindow({
backgroundColor:randomColor(),
fullscreen:true,
barColor:randomColor(),
navTintColor:randomColor(),
translucent:true
});
var b1 = Ti.UI.createButton(
{
title:'NEW',
borderColor:'black',
borderWidth:2,
width:200,
height:60,
borderRadius:30,
tintColor:'red',
backgroundColor:'white'
});
b1.addEventListener('click',function(){
navWin.openWindow(buildNewWindow({
backgroundColor:randomColor(),
fullscreen:true,
barColor:randomColor(),
navTintColor:randomColor(),
translucent:true
}));
});
rootWin.add(b1);
var navWin = Ti.UI.iOS.createNavigationWindow({window:rootWin});
function buildNewWindow(args){
var _self = Ti.UI.createWindow(args);
var btn_new = Ti.UI.createButton(
{
title:'NEW',
top:20,
borderColor:'black',
borderWidth:2,
width:200,
height:60,
borderRadius:30,
tintColor:'red',
backgroundColor:'white'
});
_self.add(btn_new);
btn_new.addEventListener('click', function(){
navWin.openWindow(buildNewWindow({
backgroundColor:randomColor(),
fullscreen:true,
barColor:randomColor(),
navTintColor:randomColor(),
translucent:true
}
)
);
});
var btn_back = Ti.UI.createButton(
{
title:'< BACK',
bottom:40,
borderColor:'white',
borderWidth:2,
width:200,
height:60,
borderRadius:30,
tintColor:'white',
backgroundColor:'#333'
});
_self.add(btn_back);
btn_back.addEventListener('click', function(){
navWin.closeWindow(_self);
});
return _self;
}
navWin.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment