【发布时间】:2017-10-20 09:58:55
【问题描述】:
在钛经典中,我这样做是为了使 UI 适应各种 iPhone 屏幕尺寸。
return parseInt((Ti.Platform.displayCaps.platformWidth * val) / 320);
从对象在宽度为 320 磅的设备中的基本尺寸开始调整对象的尺寸。
测试代码
var win = Ti.UI.createWindow();
var testView1 = Ti.UI.createView({
width : Ti.UI.FILL,
height : Ti.UI.SIZE,
top : 0,
backgroundColor : "#2196F3",
layout : "vertical"
});
var testView2 = Ti.UI.createView({
width : Ti.UI.FILL,
height : Ti.UI.SIZE,
bottom: getSize(20),
layout : "horizontal"
});
testView2.add(
Ti.UI.createView({
width : getSize(50),
height : getSize(50),
left : getSize(20),
borderRadius : getSize(25),
backgroundColor : "white"
}),
Ti.UI.createLabel({
width : getSize(200),
height : Ti.UI.SIZE,
left : getSize(20),
text : "Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua.",
color : "white",
font : {
fontSize : getSize(14)
}
})
);
testView1.add(
Ti.UI.createLabel({
width : Ti.UI.FILL,
height : getSize(50),
top : getSize(20),
text : "Lorem ipsum",
color : "white",
font : {
fontSize : getSize(14),
fontWeight : "bold"
},
textAlign : "center",
}),
testView2
);
win.add(testView1);
win.open();
function getSize(val){
return parseInt((Ti.Platform.displayCaps.platformWidth * val) / 320);
}
没有 getSize() 函数的结果
getSize() 函数的结果
这是一个好方法吗?
【问题讨论】:
标签: titanium appcelerator appcelerator-titanium