【问题标题】:Change Titanium Active Tab Highlight Color更改 Titanium 活动选项卡突出显示颜色
【发布时间】:2011-04-22 20:10:08
【问题描述】:

如何更改 Titanium 中已选择/处于活动状态的选项卡的蓝色突出显示颜色?是否可以为选定的选项卡定义活动状态图标?

【问题讨论】:

  • 从 G 的快速搜索中,我发现您需要创建自己的自定义模块才能使用 SDK 在 Titanium 之外执行此操作。除非 Appcelerator 工作人员计划这样做,否则目前不可用。
  • 我认为它比这更复杂,我认为这是一个 iOS 问题而不是 appcelerator。
  • 感谢您的意见。我想我已经想出了一个解决方案,我将完全放弃标签,而只是在视图中使用按钮,类似于标签。

标签: javascript iphone mobile titanium


【解决方案1】:

理想的解决方案是使用:

Ti.UI.createTab({
    icon: '/images/inactive_icon.png',
    activeIcon: '/images/active_icon.png',
});

需要 Ti SDK 3.1.0

【讨论】:

    【解决方案2】:

    一种选择是将元素添加到选项卡组本身。然后,当标签获得焦点时,您可以在其上方显示图像。

    这是必要的,因为(如上面的 cmets 所述),iOS 不允许我们自定义标签的颜色或突出显示样式。

    下面是一个示例,说明如何实现这一目标。如果您只想选择不同的图像,您可以做一些涉及较少的事情。

    希望这会有所帮助! -道森

    /**
     * Override a tab group's tab bar on iOS.
     *
     * NOTE: Call this function on a tabGroup AFTER you have added all of your tabs to it! We'll look at the tabs that exist
     * to generate the overriding tab bar view. If your tabs change, call this function again and we'll update the display.
     *
     * @param tabGroup The tab group to override
     * @param backgroundOptions The options for the background view; use properties like backgroundColor, or backgroundImage.
     * @param selectedOptions The options for a selected tab button.
     * @param deselectedOptions The options for a deselected tab button.
     */
    function overrideTabs(tabGroup, backgroundOptions, selectedOptions, deselectedOptions) {
    
        // are we restyling the tab groups?
        if (tabGroup.overrideTabs) {
            tabGroup.remove(tabGroup.overrideTabs);
        }
    
        // a bunch of our options need to default to 0 for everything to position correctly; we'll do it en mass:
        deselectedOptions.top = deselectedOptions.bottom = selectedOptions.top = selectedOptions.bottom = backgroundOptions.left
                = backgroundOptions.right = backgroundOptions.bottom = 0;
    
        // create the overriding tab bar using the passed in background options
        backgroundOptions.height = 50;
        var background = Ti.UI.createView(backgroundOptions);
    
        // and create our individual tab buttons
        var activeTab = null, increment = 100 / tabGroup.tabs.length;
        deselectedOptions.width = selectedOptions.width = String(increment) + '%';
        for (var i = 0, l = tabGroup.tabs.length; i < l; i++) {
            (function(i) {
                var tab = tabGroup.tabs[i];
                selectedOptions.left = deselectedOptions.left = String(increment * i) + '%';
    
                // set the title of the button to be the title of the tab
                selectedOptions.title = deselectedOptions.title = tab.title;
    
                tab.selected = Ti.UI.createButton(selectedOptions);
                tab.deselected = Ti.UI.createButton(deselectedOptions);
                tab.deselected.addEventListener('click', function() {
                    if (activeTab) {
                        activeTab.selected.visible = false;
                    }
                    tab.selected.visible = true;
                    activeTab = tab;
                    tabGroup.setActiveTab(i);
                });
                tab.selected.visible = false;
                background.add(tab.deselected);
                background.add(tab.selected);
            })(i);
        }
    
        tabGroup.add(background);
        tabGroup.overrideTabs = background;
    
        // "click" the first tab to get things started
        tabGroup.tabs[0].deselected.fireEvent('click');
    }
    
    /*
     The rest is a typical new project -- a tab group with three tabs.
     */
    
    var tabGroup = Ti.UI.createTabGroup();
    tabGroup.addTab(Ti.UI.createTab({
        title: 'Tab 1',
        window: Ti.UI.createWindow({ title: 'Tab 1', backgroundColor: '#fff' })
    }));
    tabGroup.addTab(Ti.UI.createTab({
        title: 'Tab 2',
        window: Ti.UI.createWindow({ title: 'Tab 2', backgroundColor: '#fff' })
    }));
    tabGroup.addTab(Ti.UI.createTab({
        title: 'Tab 3',
        window: Ti.UI.createWindow({ title: 'Tab 3', backgroundColor: '#fff' })
    }));
    
    /*
     Now call our overrideTabs function!
     */
    overrideTabs(
        tabGroup,
        { backgroundColor: '#f00' },
        { backgroundColor: '#999', color: '#000', style: 0 },
        { backgroundColor: '#333', color: '#888', style: 0 }
    );
    
    tabGroup.open();
    

    (摘自我的原始要点:https://gist.github.com/853935

    【讨论】:

      猜你喜欢
      • 2016-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      • 2016-04-12
      • 2022-01-20
      • 1970-01-01
      相关资源
      最近更新 更多