2014-01-07 126 views
0

所以我必須將對象添加到Titanium的窗口中,但它們只會在我將它們添加到TableViewRow而不是窗口時顯示。我想添加的兩個項目是profileIcon和flowLabel。這是我在我的頭得到:Titanium:標籤和圖像不會顯示在窗口中

Header

var defaultFontSize = Ti.Platform.name === 'android' ? 16 : 14; 

// Function to test if device is iOS 7 or later 
function isiOS7Plus() 
{ 
    // iOS-specific test 
    if (Titanium.Platform.name == 'iPhone OS') 
    { 
     var version = Titanium.Platform.version.split("."); 
     var major = parseInt(version[0],10); 

     // Can only test this support on a 3.2+ device 
     if (major >= 7) 
     { 
      return true; 
     } 
    } 
    return false; 
} 

var iOS7 = isiOS7Plus(); 
var theTop = iOS7 ? 59 : 0; 

var window = Ti.UI.createWindow({top:theTop}); 

// Set the background color to non-black to see the status bar 
// Or set the Window statusBarStyle property to a non-default value 
Ti.UI.setBackgroundColor('#232a35'); 
var win = Ti.UI.createWindow({ 
    // Remove the status bar 
    // fullscreen: true 
    // Moves the Window below the status bar 
    top: theTop 
}); 

var profileIcon = Ti.UI.createImageView({ 
    image: 'img/[email protected]', 
    left:15, 
    verticalAlign: 'center', 
    width:12, height:14 
}); 
win.add(profileIcon); 

var flowLabel = Ti.UI.createLabel({ 
    color:'white', 
    font:{fontFamily:'Lato-Bold', fontSize:defaultFontSize+2}, 
    text:'Flöde', 
    textAlign: center, 
    verticalAlign: center 
}); 
win.add(flowLabel); 
win.open(); 

這是我的BTW開發第一個應用程序和我以前的技能是基於HTML和CSS,所以如果你有任何其他在途中分享提示,請讓我知道。

乾杯!

回答

0

他們顯示在你的桌子後面,這就是爲什麼你沒有看到他們。既沒有頂部也沒有底部,所以將它們定位在window的中心。

最簡單的解決方案是添加一個頂部尺寸的視圖,然後添加標籤和圖像。

var win = Ti.UI.createWindow({ 
    backgroundColor: '#fff', 
      fullscreen: true 
}); 

var top = Ti.UI.createView({ 
    top: 0, height: 60 
}); 
top.add(Ti.UI.createLabel({ text: 'My Label', textAlign: 'center', color: '#000', left: 10 })); 
top.add(Ti.UI.createImageView({ image: 'my/image.png', width: 40, height: 40, right: 10 })); 
win.add(top); 

win.add(Ti.UI.createTableView({ 
    top: 60 
})); 

win.open();