Last active
August 29, 2015 14:07
-
-
Save njncalub/161e35e9cb8e3cc5e3a3 to your computer and use it in GitHub Desktop.
sample usage of the centerImageView.js file
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
var win, parentView, imageView; | |
var initView; | |
// copy the centerImageView code here | |
initView = function() { | |
win = Ti.UI.createWindow({ | |
backgroundColor: "#cccccc" | |
}); | |
parentView = Ti.UI.createView({ | |
height: Ti.Platform.displayCaps.platformHeight, | |
width: Ti.Platform.displayCaps.platformWidth, | |
borderRadius: 0 | |
}); | |
imageView = Ti.UI.createImageView({ | |
image: "/images/my_image.jpg" | |
}); | |
// we assume here that the image has a dimension of 600x400, therefore the ratio is 3:2. | |
// then you can pass {width: 3, height: 2} or {width: 600, height: 400} as the first argument. | |
// you can also call this after postlayout if you don't know the dimension of the image. | |
// you can then pass the imageView itself as the first argument. | |
centerImageView({ | |
width: 3, | |
height: 2 | |
}, parentView, imageView); | |
parentView.add(imageView); | |
win.add(parentView); | |
win.open(); | |
}; | |
initView(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment