width = 20% のビューを作成しています。その整数値を取得するにはどうすればよいですか。
var v = Ti.UI.createView({
width: '20%',
left: '10%',
height: '40%',
top: '10%'
});
v.width を数字に変換する必要があります。どうやってやるの?
width = 20% のビューを作成しています。その整数値を取得するにはどうすればよいですか。
var v = Ti.UI.createView({
width: '20%',
left: '10%',
height: '40%',
top: '10%'
});
v.width を数字に変換する必要があります。どうやってやるの?
これを試してください:
var screenWidth = Titanium.Platform.displayCaps.platformWidth;
var v = Ti.UI.createView({
width: screenWidth/5 ,
left: '10%',
height: '40%',
top: '10%'
});
それを行う機能があります:
function turnPercentToDp(percent){
var dp = 0;
if(percent){
if(_.isString(percent) && percent.indexOf('%')>0) {
percent = parseFloat(percent.slice(0, percent.indexOf('%')))/100;
}else{
if(percent > 1){
percent = parseFloat(percent)/100;
}
}
dp = Math.ceil((OS_IOS ? Ti.Platform.displayCaps.platformWidth : (Ti.Platform.displayCaps.platformWidth/Ti.Platform.displayCaps.logicalDensityFactor))*percent);
}
return dp;
}