2

好的,伙计们——我不得不承认,随着 Titanium 的发展继续让我感到沮丧,我的挫败感正在增加。我所做的每一个改变,无论它看起来多么无害,似乎都以一种完全出乎意料的方式破坏了其他东西。

今天,我只是想为视图添加标签,但它没有显示。

// UI Factory Include
var Inova = {};
Ti.include( '_ui.js' );

var win = Ti.UI.currentWindow;
win.layout = 'vertical';

// Header
win.add( Inova.ui.createHeaderView() );

// body
var body = Ti.UI.createView({
    backgroundColor:'#00f', // Should see no blue
    backgroundImage: '/images/body.png',
    height: 350,
    layout: 'vertical',
});
var label = Ti.UI.createLabel({
    color: '#000',
    text: 'Show me the label...please?',
    textAlign: 'center',
});
body.add( label );

win.add( body );

我知道我必须错过一些非常愚蠢和基本的东西,但我认为我已经失去了看到显而易见的一切的能力。帮助?

4

2 回答 2

4

我认为您需要在标签中明确设置宽度/高度。您可以将其设置为 width: 'auto', height: 'auto' 但必须设置。

(奇怪的是,根据我的经验,这在 Andriod 中是不正确的)。

于 2011-10-20T14:45:52.057 回答
1

每当我对 API 感到困惑时,我都会回到基础。尝试这个:

创建一个名为 myTest 的新项目。在 apps.js 文件中,将以下代码添加到文件底部最后一行上方

var win3 = Titanium.UI.createWindow({  
  title:'Tab 3',
  backgroundColor:'#fff'
});
var tab3 = Titanium.UI.createTab({  
  icon:'KS_nav_ui.png',
  title:'Tab 3',
  window:win3
});

var label3 = Titanium.UI.createLabel({
 color:'#999',
  text:'I am Window 3',
  font:{fontSize:20,fontFamily:'Helvetica Neue'},
  textAlign:'center',
  width:'auto'
});

var txtLabel = Ti.UI.createLabel({
  color: '#000',
  text: 'Show me the label...please?',
  textAlign: 'center',
  left: 100,
  top: 50
});
win3.add( txtLabel );
win3.add(label3);

您的标签 txtLabel 现在将出现在 tab3 上的 label3 下方。我尝试使用您提供的代码,但未能使其正常工作。因此,从显示标签的基本页面开始,然后添加其他组件,直到获得预期结果。

希望有帮助。

于 2011-10-20T14:45:26.673 回答