Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8300] iOS: Width and height of label is not correctly retrieved.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-03-27T09:26:17.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sn/a
ComponentsiOS
Labelsregression
ReporterDevang Gandhi
AssigneeVishal Duggal
Created2012-03-25T17:07:31.000+0000
Updated2017-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);

Comments

  1. Vishal Duggal 2012-03-26

    label2 is never attached to the window so dynamic size will always be 0
  2. Shawn Lipscomb 2012-03-27

    Have you tried label2.toImage().width ? Edit: I have confirmed that label2.toImage().width will give you the number you want.
  3. Tommy Leung 2012-03-27

    The size is available in 1.8.1 and 1.8.2.
  4. Vishal Duggal 2012-03-27

    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.
  5. Vishal Duggal 2012-03-27

    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.
  6. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source