簡體   English   中英

TableView中的多行標簽

[英]Multi-line label in TableView

如何在我的tableview中添加多行標簽,如此屏幕中的多標簽(多任務手勢下面的標簽): http//cl.ly/6g0B

這實際上是通過創建headerView完成的(至少在Titanium中)。

headerLabel = Ti.UI.createLabel({
    text: 'line 1'
});

headerView = Ti.UI.createView({
    height: 60
});

headerSection = Ti.UI.createTableViewSection();

headerView.add(headerLabel);
headerSection.add(headerView);
tableView.add(headerSection);

您可以向視圖添加更多labels並設置height以進行相應調整。 您還需要使用data填充headerSection

您需要將您的tableview分組(至少在定位iOS設備時)。 然后,創建一個包含行的表視圖部分,並通過其headerView屬性將多行標簽添加到該部分

查看TableViewSection視圖的文檔: http//developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TableViewSection-object

一個簡短的例子 - 它是未經測試的抱歉,我現在沒有Mac,但原則是合理的。 您可以創建標題視圖,創建節,設置節標題視圖,向節添加一些單元格,並為表格提供一系列節:

var tableView = Ti.UI.createTableView({
   style: Ti.UI.iPhone.TableViewStyle.GROUPED
});
var tableData = [];

var multiLineLabelView = Ti.UI.createView();
var line1 = Ti.UI.createLabel({
     text: 'Some text'
});
var line2 = Ti.UI.createLabel({
     text: 'More text',
     top: 20
});
multiLineLabelView.add(line1);
multiLineLabelView.add(line2);

var section = Ti.UI.createTableViewSection({
    headerView: multiLineLabelView,
    height: 40
});

var row1 = Ti.UI.createTableViewRow({
    title: 'Row 1'
});

var row2 = Ti.UI.createTableViewRow({
    title: 'Row 2'
});

section.add(row1);
section.add(row2);

tableData.push(section);
tableView.data = tableData;

需要注意的重要一點是,您只需要一個表 - 在您給出的示例中,行被分組為多個部分,其中一些部分具有標題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM