[TIMOB-8300] iOS: Width and height of label is not correctly retrieved.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-03-27T09:26:17.000+0000 |
Affected Version/s | Release 2.0.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | regression |
Reporter | Devang Gandhi |
Assignee | Vishal Duggal |
Created | 2012-03-25T17:07:31.000+0000 |
Updated | 2017-03-24T18:13:46.000+0000 |
Description
label.width gives incorrect value, when retrieved. The label is not rendered by the window, but well defined in the code.
This works in 1.8.1, and 1.8.2, but fails in 2.0
var win1 = Titanium.UI.createWindow({
backgroundColor:'white'
});
var label = Ti.UI.createLabel({
text: ''
});
win1.add(label);
setTimeout(function(){
label.text = "show up";
Ti.API.info(label.text);
}, 1000);
win1.open();
var label2 = Ti.UI.createLabel({
text: 'asdadasd asdaj lsdak l',
width: 'auto'
});
Ti.API.info("label2 width: " + label2.size.width);
label2 is never attached to the window so dynamic size will always be 0
Have you tried label2.toImage().width ? Edit: I have confirmed that label2.toImage().width will give you the number you want.
The size is available in 1.8.1 and 1.8.2.
The reason it worked in 1.8.X is because we would blindly create the view every time the size property was accessed. Now we ensure that the view is attached to the UI framework when you access the size property. The reason for this change is to keep the behavior consistent with the rect property of the views.
The
size
property has been redefined and values returned by size.width and size.height must match the values returned by rect.width and rect.height when no transform is applied to the view.Closing ticket as invalid with reference to the above comments.