Please note: This question relates to the Appcelerator Titanium platform, not the stock iOS SDK.
I'm making a tag cloud with a layout: horizontal
view. I'm most of the way there, but I can't get the final Titanium.UI.Label
on a line to wrap if it doesn't fit. Instead, it gets ellipsized (in a useless manner).
Is there a way I can preven开发者_运维知识库t this on iOS? Seems to work fine on Android.
If you try to set the label width to auto, Titanium will calculate the label width in runtime. It make sense to get a ellipsized label in horizontal view.
You may need to determine the dynamic label width in your tag cloud case. But just leave it to titanium, you just need to change the dynamic width to static width with this tricky code.
for (var i = 0; i < data.length; i++) {
var label = Ti.UI.createLabel({ text: data[i], width: 'auto', height: 20,left: 5, top: 5});
label.width = label.width + 5; //this determine width in runtime assign back to static width
view.add(label);
}
The iPhone's answer to this is minimumFontSize
but that makes no sense in a tag cloud... Have you considered adding this to a horizontal scrollview and setting the contentWidth
to auto
?
Also does each of your label have it's width
set to 'auto'
? I imagine setting that would cause the word to overflow the layout
and be pushed down to the next line.
精彩评论