【问题标题】:Titanium adding a label to a viewTitanium 为视图添加标签
【发布时间】:2011-10-20 12:52:10
【问题描述】:

好吧,伙计们——我不得不承认,随着 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 );

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

【问题讨论】:

    标签: titanium titanium-mobile


    【解决方案1】:

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

    (奇怪的是,根据我的经验,这在 Andriod 中并非如此)。

    【讨论】:

    • 看来你是对的。我想我只是没有想到我必须对一切如此绝对明确。谢谢。
    【解决方案2】:

    每当我对 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 下方。我尝试使用您提供的代码,但未能使其正常工作。因此,从显示标签的基本页面开始,然后添加其他组件,直到获得预期结果。

    希望对您有所帮助。

    【讨论】:

    • 见鬼,我以为这些的基础。创建视图。将标签放在视图中。 :-)
    猜你喜欢
    • 2015-03-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 2019-01-22
    相关资源
    最近更新 更多