Skip to content

Instantly share code, notes, and snippets.

@LuizGadao
Forked from skypanther/app.js
Last active January 3, 2016 13:59
Show Gist options
  • Save LuizGadao/8473015 to your computer and use it in GitHub Desktop.
Save LuizGadao/8473015 to your computer and use it in GitHub Desktop.
// implement like this:
var window = Ti.UI.createWindow({
backgroundColor:'#fff'
});
// draw the gridlines first so your other elements stack on top of them
// without requiring you to set the z-index property of each
var grid = require('gridlines');
grid.drawgrid(10,window);
exports.drawgrid = function(gridspacing, win, color, colorLabel) {
// gridspacing = integer
// win = window to which the grid will be added
// color = optional color for lines
// colorLabel = optional color for text
var clr = (color) ? color : '#dedede';
var clrLabel = (colorLabel) ? colorLabel : '#ffffff';
var numhoriz = Math.ceil(Ti.Platform.displayCaps.platformHeight / gridspacing);
var numvert = Math.ceil(Ti.Platform.displayCaps.platformWidth / gridspacing);
for(h=0; h<numhoriz;h++) {
win.add( Ti.UI.createView({
height:1,
width:'100%',
backgroundColor:clr,
top: h*gridspacing,
left:0,
opacity:0.5,
touchEnabled:false
}) );
win.add( Ti.UI.createLabel({
text:'' + (h * gridspacing),
color:clrLabel,
font:{fontSize:8},
top:h*gridspacing + 2,
left:2,
touchEnabled:false
}) );
}
for(v=0; v<numvert;v++) {
win.add( Ti.UI.createView({
width:1,
height:'100%',
backgroundColor:clr,
left: v*gridspacing + 1,
top:0,
opacity:0.5,
touchEnabled:false
}) );
win.add( Ti.UI.createLabel({
text:(v*gridspacing),
color:clrLabel,
font:{fontSize:8},
top:0,
left:v*gridspacing + 1,
touchEnabled:false
}) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment