Issue
ScrollView Children do not size properly. Label 6 doesn't calculate size properly (uses remaining visible space), but Label 7 and Label 1-5 all calculate size properly.
Tested on
iOS 5 simulator
Expected behavior
Children should calculate based on contentWidth. Example will run under 1.8.2. When run under 1.8.2 sizes are as expected.
Current behavior
Instead, children use visible width value to calculate their size. As seen in screenShot with Titanium SDK 2.0.1.GA2
Repro sequence
var view = Ti.UI.createScrollView({
borderWidth: 1,
borderColor: '#f00',
layout:'horizontal',
height: 35,
contentHeight: 35,
contentWidth: 'auto',
left: 0,
right: 0
});
var items = ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5', 'Label 6', 'Label 7'];
items.forEach(function(item) {
var width = (Ti.UI.SIZE == undefined) ? 'auto': Ti.UI.SIZE; //So example works under 1.8.2 or 2.0.1
var tLabel = Ti.UI.createLabel({
touchEnabled: false,
text:' ' + item + ' ', //To add inner padding
backgroundColor: '#6CF',
borderColor: '#000',
borderWidth: 1,
borderRadius: 5,
color: '#FF0080',
right: 5,
top: 1,
width:width,
height:22,
font: {
fontSize: 13
},
textAlign: 'center'
});
view.add(tLabel);
});
var rootWin = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
// add table view to the window
rootWin.add(view);
rootWin.open();
API Docs
http://docs.appcelerator.com/titanium/2.0/index.html#!/api/Titanium.UI.ScrollView-property-contentWidth
*Related issue:* For some reason NSString's - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode method truncates the string having trailing spaces when given _size_ parameter width is equal to the expected return width. E.g. for size=(61,20) it returns (60, 16), but for size=(60,20) it returns (56, 16). if there is no space, the returned values are same.
*Possible fix:*
PR pending https://github.com/appcelerator/titanium_mobile/pull/2338
Closing issue Tested with Ti Studio build 2.1.0.201206200844 Ti Mobile SDK 2.1.0.v20120619172256 hash rd3a84b13 OSX Lion 10.7.3 iPhone 4S OS 5.1 The expected behavior is shown