1

是否可以在 Titanium 标签中指定换行文本行之间的间距?我看不到这样做的方法吗?

4

1 回答 1

5

实现它的一种方法是在属性字符串中使用基线偏移:

var win = Ti.UI.createWindow();

var text = "The history of all hitherto existing society is the history of class struggles. Freeman and slave, patrician and plebeian, lord and serf, guild-master and journeyman, in a word, oppressor and oppressed, stood in constant opposition to one another, carried on an uninterrupted, now hidden, now open fight, a fight that each time ended, either in a revolutionary reconstitution of society at large, or in the common ruin of the contending classes.";

var attr = Ti.UI.iOS.createAttributedString({
    text: text,
    attributes: [
        {
            type: Ti.UI.iOS.ATTRIBUTE_BASELINE_OFFSET,
            value: 20,
            range: [0,250]
        }  
    ]
});

var label = Ti.UI.createLabel({
    attributedString: attr,
    color:'white',
    width:Ti.UI.FILL,
    height:500
});
win.add(label);

win.open();
于 2015-03-13T15:49:17.913 回答