lib/motion-tab/tab_bar.rb in motion-tab-0.0.1 vs lib/motion-tab/tab_bar.rb in motion-tab-0.1.2

- old
+ new

@@ -1,34 +1,41 @@ module MotionTab - module TabBar - def createTabBarControllerFromData(data) - main_view = MainViewController.alloc.initWithNibName(nil, bundle: nil) - settings_view = SettingsViewController.alloc.initWithNibName(nil, bundle: nil) - - mt_tab_controllers = [] + class TabBar + class << self + def createTabBarControllerFromData(data) + mt_tab_controllers = [] - data.each do |tab| - tab[:badgeNumber] = 0 unless tab[:badgeNumber] - - viewController = tab[:viewController].alloc.init - viewController.tabBarItem = tabBarIcon(tab[:systemIcon], tab[:badgeNumber]) if tab[:systemIcon] - - if tab[:navigationController] - controller = UINavigationController.alloc.initWithRootViewController(viewController) - else - controller = viewController - end + data.each do |tab| + tab[:badgeNumber] = 0 unless tab[:badgeNumber] + tab[:tag] = 0 unless tab[:tag] + + viewController = tab[:viewController].alloc.init + viewController.tabBarItem = tabBarIcon(tab[:systemIcon], tab[:tag]) if tab[:systemIcon] + viewController.tabBarItem.badgeValue = tab[:badgeNumber].to_s unless tab[:badgeNumber].nil? || tab[:badgeNumber] <= 0 + + if tab[:navigationController] + controller = UINavigationController.alloc.initWithRootViewController(viewController) + else + controller = viewController + end - mt_tab_controllers << controller - end + if tab[:title] + controller.tabBarItem.title = tab[:title] + else + controller.tabBarItem.title = viewController.title + end - tabBarController = UITabBarController.alloc.init - tabBarController.viewControllers = mt_tab_controllers + mt_tab_controllers << controller + end - return tabBarController - end + tabBarController = UITabBarController.alloc.init + tabBarController.viewControllers = mt_tab_controllers - def tabBarItem(icon, tag = 0) - return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag) + return tabBarController + end + + def tabBarIcon(icon, tag = 0) + return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag) + end end end end \ No newline at end of file