function onImgListRender(box: Laya.Box) {
let model = box.dataSource;
let panel = box.getChildByName('panel') as Laya.Panel;
let img = panel.getChildByName('img') as Laya.Image;
img.skin = model;
let reset = function () {
let source = img.source;
if (source) {
//Math.max是左边的效果,min是右边的效果
let ratio = Math.max(source.width, source.height) / 100;
img.width = source.width / ratio;
img.height = source.height / ratio;
}
}
reset();
img.on(Laya.Event.LOADED, this, () => {
reset();
});
}
1 个回复
umi
赞同来自: 沉梦昂志
myTestUI.imgList.spaceX = myTestUI.imgList.spaceY = 50;
myTestUI.imgList.array = ['comp/bg.png', 'comp/btn_close.png', 'comp/button.png', 'comp/image.png'];
myTestUI.imgList.renderHandler = new Laya.Handler(this, onImgListRender);
function onImgListRender(box: Laya.Box) {
let model = box.dataSource;
let panel = box.getChildByName('panel') as Laya.Panel;
let img = panel.getChildByName('img') as Laya.Image;
img.skin = model;
let reset = function () {
let source = img.source;
if (source) {
//Math.max是左边的效果,min是右边的效果
let ratio = Math.max(source.width, source.height) / 100;
img.width = source.width / ratio;
img.height = source.height / ratio;
}
}
reset();
img.on(Laya.Event.LOADED, this, () => {
reset();
});
}