This is really just ripped straight from the WidgetDemo in the SampleCode directory, but I thought it might be useful.
The WidgetDemo has a tab bar at the bottom but is pretty easy to customise. The code below makes customising it a single line of code.
Add your tabbar (after creating a parent display group for it) like this:
[lua]newTabBar( tabBarGroup, { {text=“Products”, func=showMenu}, {text=“Near Me”, func=showMap}, {text=“Dates”, func=showCalendar}, } )[/lua]
The text values are simply the labels to show under each tab and the func values are callback functions for you to define your own actions. Typically, these would simply hide and show display groups for the content of the application.
And the function to be called is this:
[lua]function newTabBar( parent, items )
– create buttons table for the tab bar
local tabButtons = {}
for i=1, #items do
tabButtons[#tabButtons+1] =
{
label=items[i].text,
up=“assets/tabIcon.png”,
down=“assets/tabIcon-down.png”,
width=32, height=32,
onPress=items[i].func,
selected=(i == 1)
}
end
– create a tab-bar and place it at the bottom of the screen
local demoTabs = widget.newTabBar{
top=display.contentHeight-50,
buttons=tabButtons
}
– insert tab bar into display group
parent:insert( demoTabs.view )
end[/lua]
Obviously, this uses the same icon for each tab, but as the input to the function is just a table of values that is simple to change. [import]uid: 8271 topic_id: 27236 reply_id: 327236[/import]
[import]uid: 84637 topic_id: 27236 reply_id: 110709[/import]