如何在Titanium JS中创建带按钮的标题栏?

时间:2014-02-21 20:59:28

标签: titanium appcelerator titanium-alloy

我正在使用 Titanium Alloy 来构建应用,我正在尝试创建一个带有按钮的标题栏,类似于联系人应用,如下图所示:

a header bar on the iPhone with buttons in it

此标题中间有标题,按钮位于网站。

我一直在寻找在Titanium中实现这一目标的方法,但我还找不到任何东西。似乎这不在文档中,我是否需要创建完全自定义的东西?

我试图在导航视图中添加一个按钮,但它不起作用 - 它会出现一个错误,指出导航视图的子元素必须是一个窗口。

如果可能的话,我想用Alloy创建它。

1 个答案:

答案 0 :(得分:2)

创建这个非常简单的视图。唯一的技巧是使用NavigationWindow包装Window,就像你提到的错误一样。创建NavBar按钮并将其附加到控制器中。据我记忆,你不能在xml文件中创建它们。但是,通过使用$ .UI.create()方法,您可以确保所有类和样式也适用于它们。

的index.html:

<Alloy>
    <NavigationWindow>
        <Window title="Contacts" id="contacts">
            <SearchBar hintText="Search" />
            <TableView />
        </Window>
    </NavigationWindow>
</Alloy>

index.js:

$.contacts.leftNavButton = $.UI.create('Button', { title: 'Groups' });
$.contacts.rightNavButton = $.UI.create('Button', { systemButton: Ti.UI.iPhone.SystemButton.ADD });

$.index.open();

index.tss:

"Window": {
    backgroundColor: "white",
    layout: "vertical",
},
相关问题