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

- old
+ new

@@ -1,41 +1,61 @@ module MotionTab class TabBar class << self def createTabBarControllerFromData(data) + tabBarController = UITabBarController.alloc.init + tabBarController.viewControllers = self.tabControllersFromData(data) + + return tabBarController + end + + def tabBarIcon(icon, tag = 0) + return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag) + end + + def tabBarIconCustom(title, imageName, tag = 0) + iconImage = UIImage.imageNamed(imageName) + return UITabBarItem.alloc.initWithTitle(title, image:iconImage, tag:tag) + end + + def tabControllersFromData(data) mt_tab_controllers = [] 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 << self.controllerFromTabData(tab) + end - if tab[:title] - controller.tabBarItem.title = tab[:title] - else - controller.tabBarItem.title = viewController.title - end + return mt_tab_controllers + end - mt_tab_controllers << controller + def controllerFromTabData(tab) + tab[:badgeNumber] = 0 unless tab[:badgeNumber] + tab[:tag] = 0 unless tab[:tag] + + viewController = tab[:viewController].alloc.init + + if tab[:navigationController] + controller = UINavigationController.alloc.initWithRootViewController(viewController) + else + controller = viewController end - tabBarController = UITabBarController.alloc.init - tabBarController.viewControllers = mt_tab_controllers + controller.tabBarItem = self.tabBarItem(tab) + controller.tabBarItem.title = controller.title unless tab[:title] - return tabBarController + return controller end - def tabBarIcon(icon, tag = 0) - return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag) + def tabBarItem(tab) + title = "Untitled" + title = tab[:title] if tab[:title] + + tabBarItem = tabBarIcon(tab[:systemIcon], tab[:tag]) if tab[:systemIcon] + tabBarItem = tabBarIconCustom(title, tab[:icon]) if tab[:icon] + + tabBarItem.badgeValue = tab[:badgeNumber].to_s unless tab[:badgeNumber].nil? || tab[:badgeNumber] <= 0 + + return tabBarItem end end end end \ No newline at end of file