-
-
Save rightson/1480893 to your computer and use it in GitHub Desktop.
Draw gridlines in a Titanium window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.drawgrid = function(gridspacing, win, color) { | |
// gridspacing = integer | |
// win = window to which the grid will be added | |
// color = optional color for lines | |
var clr = (color) ? color : '#dedede'; | |
var numhoriz = Math.ceil(Ti.Platform.displayCaps.platformHeight / gridspacing); | |
var numvert = Math.ceil(Ti.Platform.displayCaps.platformWidth / gridspacing); | |
for(h=0; h<numhoriz;h++) { | |
var hline = Ti.UI.createView({ | |
height:1, | |
width:'100%', | |
backgroundColor:clr, | |
top: h*gridspacing, | |
left:0 | |
}); | |
win.add(hline); | |
} | |
for(v=0; v<numvert;v++) { | |
var vline = Ti.UI.createView({ | |
width:1, | |
height:'100%', | |
backgroundColor:clr, | |
left: v*gridspacing, | |
top:0 | |
}); | |
win.add(vline); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment