2012-07-29 89 views
0

我有一个新手问题:我在Titanium for iPhone中创建的简单按钮在点击时拒绝改变颜色。最初我为这个功能使用了一个按钮;由于它没有工作,我改变了一个视图,但都不起作用。这里它是如何设置的:钛钮扣在选择时不会改变背景颜色

var quifButton = Ti.UI.createView({ // tried this with createButton, as well 
    top: 44, left: 5, width: 310, height: 42, 
    backgroundColor: '#333', 
    backgroundSelectedColor: '#fff', 
    backgroundFocusedColor: '#fff', 
    touchEnabled: true, 
    borderColor: BOR_DK, borderWidth: 2, borderRadius: 5 }); 

当我在iPhone模拟器中点击按钮/视图时,没有任何反应。任何想法,为什么这不起作用,我怎么能使它工作?

回答

2

点击与焦点不同。如果你想在点击时改变颜色,你必须添加eventlistener到按钮或视图。

quifButton.addEventListener('click', function(e){ 
    quifButton.backgroundColor = '#fff'; 
}); 

* 编辑:

backgroundSelectedColor: '#fff', 
backgroundFocusedColor: '#fff', 

这些没有在iOS的支持。

+0

即使按钮被释放后,这将保持背景色为#fff ... – 2012-07-30 09:33:24

+0

这就是他所问的。如何改变点击的颜色。 – Joonas 2012-07-30 09:40:18

+0

但是当按钮应该被释放时,按钮应该以原始样式来查看。 – 2012-07-30 11:35:48

0

你的代码对我来说工作得很好。你可以尝试让我知道它是否有效吗?

var win1 = Ti.UI.createWindow({ 
    title:'home', 
    backgroundColor:'white' 
}); 
var button1 = Ti.UI.createButton({ 
    top: 44, 
    left: 5, 
    width: 310, 
    height: 42, 
    backgroundColor: '#333', 
    backgroundSelectedColor: '#fff', 
    backgroundFocusedColor: '#fff', 
    touchEnabled: true, 
    borderWidth: 2, 
    borderRadius: 5 
}); 
win1.add(button1); 
win1.open(); 
2

这是iOS中的限制,与Titanium无关。

试试这个,而不是你要找的行为:

someBtn.addEventListener('touchstart', function() { 
    someBtn.backgroundColor = 'green'; 
    }); 

    someBtn.addEventListener('touchend', function() { 
    someBtn.backgroundColor ='blue'; 
    }); 
+0

这在ios中适用于我。 (3.1.3 Ti sdk)显然不理想,但嘿.. – 29er 2013-09-26 17:37:35

-1

使用backgroundSelectedColor: “颜色”,它会工作

+0

这不适用于iOS。 (TI 5.4.0) – Garre 2016-10-13 09:51:38

0

您可以使用backgroundSelectedColor:在TSS “#的ColorCode”。希望它能工作