1

我正在 Titanium 中开发基于 tableView 的应用程序。我需要在我的表格视图行中显示长文本内容。

当我这样做时,我的行看起来像:

多行

这是我用来创建表格视图行的代码。

var row = Ti.UI.createTableViewRow({
        backgroundColor : '#F0F0F0',
        color           : 'black',
        font            : { fontSize:10 ,fontWeight:'bold',fontFamily:'Arial'},
        height          :'80',
        title           : firstRowContent
     });

我的问题是我需要将文本包装在我的表格视图行中,并且需要以多行显示它。

在 iOS 中有lineBreakModenumberOfLines属性。我可以轻松做到。

有什么办法可以用钛做吗?我搜索了很多,但每个人都说在文本之间放置一个“ \n ”或添加多个标签。

这些是我提到的链接:

  1. 多行标签
  2. 按钮和表格视图项中的多行文本 textwrap 换行符
  3. 在标签内显示结果集(文本),多行
  4. 多行标签?
  5. 数据库中的多行表行
4

3 回答 3

4

您需要在行中放置一个标签对象。可以创建标签以包裹文本。

搜索答案时,搜索complex tableviewrow appcelerator

于 2013-01-11T00:05:17.893 回答
3

下面为我​​包装。Titanium 的默认标签行为是对其进行换行。行视图的“标题”属性是单行的。

var win = Ti.UI.createWindow({
    backgroundColor: '#fff'
});
var row = Ti.UI.createTableViewRow();
row.add(Ti.UI.createLabel({
    text: 'Gosh golly, this is a label. Cool, huh?',
    color: '#000', font: { fontSize: 32 }
}));
win.add(Ti.UI.createTableView({
    data: [ row ]
}));
win.open();

如果您要在行上设置一个高度以使包裹线不适合,那么它将为您椭圆化。

row.add(Ti.UI.createLabel({
    text: 'Gosh golly, this is a label. Cool, huh?',
    color: '#000', font: { fontSize: 32 },
    height: 40
}));

但默认情况下,它会根据您提供的内容调整大小。

于 2013-01-11T04:50:51.990 回答
2

我通过添加标签作为 tableview 行的子视图来解决此问题。

 var firstRow = Ti.UI.createTableViewRow({
        backgroundColor : '#F0F0F0',
        color           : '#555555',
        font            : { fontSize:10 ,fontFamily:'Arial'},
        height          :'auto',
       // title         : firstRowContent,
        horizontalWrap  : 'true',
        selectionStyle  : Ti.UI.iPhone.TableViewCellSelectionStyle.NONE
     });
      var firstLabel = Ti.UI.createLabel({
        text            : 'Midhun Says: Hi, How are you ? We are currently waiting for you ...',
        height          : 'auto',
        right           : '10',
        top             : '7',
        left            : '10',
        color           : '#555555',
        font            : { fontSize:15 ,fontFamily:'Arial'},
     });

firstRow.add(firstLabel);

不管怎样,谢谢大家的帮助...

于 2013-01-14T05:12:13.503 回答