motion-tab 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +29 -2
- data/lib/motion-tab/tab_bar.rb +45 -25
- data/lib/motion-tab/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Motion::Tab
|
2
2
|
|
3
|
-
|
3
|
+
Easily create a UITabBar in a RubyMotion app.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,34 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Basic usage (more documentation is forthcoming):
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
25
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
26
|
+
|
27
|
+
tabs = [
|
28
|
+
{
|
29
|
+
systemIcon: UITabBarSystemItemContacts,
|
30
|
+
navigationController: true,
|
31
|
+
viewController: ContactsViewController
|
32
|
+
}, {
|
33
|
+
title: "Custom",
|
34
|
+
icon: "custom.png",
|
35
|
+
navigationController: false,
|
36
|
+
viewController: CustomViewController
|
37
|
+
}, {
|
38
|
+
title: "Settings",
|
39
|
+
icon: "settings.png",
|
40
|
+
navigationController: true,
|
41
|
+
viewController: SettingsViewController
|
42
|
+
}
|
43
|
+
]
|
44
|
+
|
45
|
+
@window.rootViewController = MotionTab::TabBar.createTabBarControllerFromData(tabs)
|
46
|
+
@window.makeKeyAndVisible
|
47
|
+
end
|
48
|
+
```
|
22
49
|
|
23
50
|
## Contributing
|
24
51
|
|
data/lib/motion-tab/tab_bar.rb
CHANGED
@@ -2,39 +2,59 @@ module MotionTab
|
|
2
2
|
class TabBar
|
3
3
|
class << self
|
4
4
|
def createTabBarControllerFromData(data)
|
5
|
+
tabBarController = UITabBarController.alloc.init
|
6
|
+
tabBarController.viewControllers = self.tabControllersFromData(data)
|
7
|
+
|
8
|
+
return tabBarController
|
9
|
+
end
|
10
|
+
|
11
|
+
def tabBarIcon(icon, tag = 0)
|
12
|
+
return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
def tabBarIconCustom(title, imageName, tag = 0)
|
16
|
+
iconImage = UIImage.imageNamed(imageName)
|
17
|
+
return UITabBarItem.alloc.initWithTitle(title, image:iconImage, tag:tag)
|
18
|
+
end
|
19
|
+
|
20
|
+
def tabControllersFromData(data)
|
5
21
|
mt_tab_controllers = []
|
6
22
|
|
7
23
|
data.each do |tab|
|
8
|
-
|
9
|
-
tab[:tag] = 0 unless tab[:tag]
|
10
|
-
|
11
|
-
viewController = tab[:viewController].alloc.init
|
12
|
-
viewController.tabBarItem = tabBarIcon(tab[:systemIcon], tab[:tag]) if tab[:systemIcon]
|
13
|
-
viewController.tabBarItem.badgeValue = tab[:badgeNumber].to_s unless tab[:badgeNumber].nil? || tab[:badgeNumber] <= 0
|
14
|
-
|
15
|
-
if tab[:navigationController]
|
16
|
-
controller = UINavigationController.alloc.initWithRootViewController(viewController)
|
17
|
-
else
|
18
|
-
controller = viewController
|
19
|
-
end
|
20
|
-
|
21
|
-
if tab[:title]
|
22
|
-
controller.tabBarItem.title = tab[:title]
|
23
|
-
else
|
24
|
-
controller.tabBarItem.title = viewController.title
|
25
|
-
end
|
26
|
-
|
27
|
-
mt_tab_controllers << controller
|
24
|
+
mt_tab_controllers << self.controllerFromTabData(tab)
|
28
25
|
end
|
29
26
|
|
30
|
-
|
31
|
-
|
27
|
+
return mt_tab_controllers
|
28
|
+
end
|
32
29
|
|
33
|
-
|
30
|
+
def controllerFromTabData(tab)
|
31
|
+
tab[:badgeNumber] = 0 unless tab[:badgeNumber]
|
32
|
+
tab[:tag] = 0 unless tab[:tag]
|
33
|
+
|
34
|
+
viewController = tab[:viewController].alloc.init
|
35
|
+
|
36
|
+
if tab[:navigationController]
|
37
|
+
controller = UINavigationController.alloc.initWithRootViewController(viewController)
|
38
|
+
else
|
39
|
+
controller = viewController
|
40
|
+
end
|
41
|
+
|
42
|
+
controller.tabBarItem = self.tabBarItem(tab)
|
43
|
+
controller.tabBarItem.title = controller.title unless tab[:title]
|
44
|
+
|
45
|
+
return controller
|
34
46
|
end
|
35
47
|
|
36
|
-
def
|
37
|
-
|
48
|
+
def tabBarItem(tab)
|
49
|
+
title = "Untitled"
|
50
|
+
title = tab[:title] if tab[:title]
|
51
|
+
|
52
|
+
tabBarItem = tabBarIcon(tab[:systemIcon], tab[:tag]) if tab[:systemIcon]
|
53
|
+
tabBarItem = tabBarIconCustom(title, tab[:icon]) if tab[:icon]
|
54
|
+
|
55
|
+
tabBarItem.badgeValue = tab[:badgeNumber].to_s unless tab[:badgeNumber].nil? || tab[:badgeNumber] <= 0
|
56
|
+
|
57
|
+
return tabBarItem
|
38
58
|
end
|
39
59
|
end
|
40
60
|
end
|
data/lib/motion-tab/version.rb
CHANGED