Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

tabbar view change label
Started by kakula Sep 07 2019 02:14 PM

3 replies to this topic
tabbar change label text
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

kakula

[GLOBAL: userInfoPane.html]
kakula
  • Enthusiast

  • 98 posts
  • Corona SDK

Hi Guys,

 

How can i change a label for one of the tabbar view buttons

 

i have a basket button, and i want to change the label of the basket button to show number of items selected so far

 

i thought it should be something close to:

 

tabBar.buttons(3):setLabel...

 

or tabBar:setLabel....

 

Regards,

Tariq



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 893 posts
  • Corona SDK

According to the documentation: https://docs.coronalabs.com/api/library/widget/newTabBar.html, there isn't a method for doing this.

 

However, if you read the source, https://github.com/coronalabs/framework-widget/blob/master/widgetLibrary/widget_tabbar.lua, you can find out how the tab bar is made and how you can manually change the texts.

 

The code is copied from the documentation sample. I only added the last line.

local widget = require( "widget" )

-- Function to handle button events
local function handleTabBarEvent( event )
    print( event.target.id )  -- Reference to button's 'id' parameter
end

-- Configure the tab buttons to appear within the bar
local tabButtons = {
    {
        label = "Tab1",
        id = "tab1",
        selected = true,
        onPress = handleTabBarEvent
    },
    {
        label = "Tab2",
        id = "tab2",
        onPress = handleTabBarEvent
    },
    {
        label = "Tab3",
        id = "tab3",
        onPress = handleTabBarEvent
    }
}

-- Create the widget
local tabBar = widget.newTabBar(
    {
        top = display.contentHeight-120,
        width = display.contentWidth,
        buttons = tabButtons
    }
)

tabBar._viewButtons[1].label.text = "I've been changed"


[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,064 posts
  • Enterprise

Please keep in mind, when we prefix a variable with an underscore, it's our intent that it be treated as a private variable (since Lua doesn't support private variables).  We do not intend for you to access those table members and reserve the right to change them at any time. 

 

Now that said, we've not touched that widget in ions. We are not likely going to be adding new features to it anytime soon. We also open-sourced the code for it, so you are free to modify the widget library to your needs (since it's all just Lua). And if you make something useful like adding an API to update a tab label, we would consider the pull request.

 

Rob



[TOPIC: post.html]
#4

kakula

[GLOBAL: userInfoPane.html]
kakula
  • Enthusiast

  • 98 posts
  • Corona SDK

@XeduR

 

this worked for me thanks

 

tabBar._viewButtons[1].label.text = "I've been changed"
 
 
@Rob
 
i'm not that good  :D  but it is great to know those facts



[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: tabbar, change label text