motion-tab 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -4
- data/lib/motion-tab/tab_bar.rb +31 -4
- data/lib/motion-tab/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# MotionTab
|
2
2
|
|
3
3
|
Easily create a UITabBar in a RubyMotion app.
|
4
4
|
|
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Basic usage (more documentation is forthcoming):
|
21
|
+
Basic usage (more documentation is forthcoming). In app/app_delegate.rb:
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
@@ -33,7 +33,7 @@ def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
33
33
|
title: "Custom",
|
34
34
|
icon: "custom.png",
|
35
35
|
navigationController: false,
|
36
|
-
viewController: CustomViewController
|
36
|
+
viewController: CustomViewController.alloc.initWithCustomInit(true)
|
37
37
|
}, {
|
38
38
|
title: "Settings",
|
39
39
|
icon: "settings.png",
|
@@ -42,11 +42,27 @@ def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
42
42
|
}
|
43
43
|
]
|
44
44
|
|
45
|
-
|
45
|
+
tabBarController = MotionTab::TabBar.createTabBarControllerFromData(tabs)
|
46
|
+
MotionTab::TabBar.select(tabBarController, title: "Settings")
|
47
|
+
# MotionTab::TabBar.select(tabBarController, tag: 0) # Selects first tab
|
48
|
+
|
49
|
+
@window.rootViewController = tabBarController
|
46
50
|
@window.makeKeyAndVisible
|
47
51
|
end
|
48
52
|
```
|
49
53
|
|
54
|
+
### Tab Options
|
55
|
+
**systemIcon:** You can **not** customize the title if you use a system icon. You can find all of them here: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html#pageNavigationLinks_bottom
|
56
|
+
|
57
|
+
**icon:** Uses an image found in /resources.
|
58
|
+
|
59
|
+
**title:** Custom title (only used if also using a custom icon). NOTE: setting self.title in a ViewController will override this value when you switch to that tab.
|
60
|
+
|
61
|
+
**navigationController:** Boolean. If true, wraps **viewController** in a UINavigationController.
|
62
|
+
|
63
|
+
**viewController:** The UIViewController class you want to load into the tab. You can also pass in an instantiated viewController.
|
64
|
+
|
65
|
+
|
50
66
|
## Contributing
|
51
67
|
|
52
68
|
1. Fork it
|
data/lib/motion-tab/tab_bar.rb
CHANGED
@@ -2,17 +2,30 @@ module MotionTab
|
|
2
2
|
class TabBar
|
3
3
|
class << self
|
4
4
|
def createTabBarControllerFromData(data)
|
5
|
+
data = self.setTags(data)
|
6
|
+
|
5
7
|
tabBarController = UITabBarController.alloc.init
|
6
8
|
tabBarController.viewControllers = self.tabControllersFromData(data)
|
7
9
|
|
8
10
|
return tabBarController
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
13
|
+
def setTags(data)
|
14
|
+
tagNumber = 0
|
15
|
+
|
16
|
+
data.each do |d|
|
17
|
+
d[:tag] = tagNumber
|
18
|
+
tagNumber += 1
|
19
|
+
end
|
20
|
+
|
21
|
+
return data
|
22
|
+
end
|
23
|
+
|
24
|
+
def tabBarIcon(icon, tag)
|
12
25
|
return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag)
|
13
26
|
end
|
14
27
|
|
15
|
-
def tabBarIconCustom(title, imageName, tag
|
28
|
+
def tabBarIconCustom(title, imageName, tag)
|
16
29
|
iconImage = UIImage.imageNamed(imageName)
|
17
30
|
return UITabBarItem.alloc.initWithTitle(title, image:iconImage, tag:tag)
|
18
31
|
end
|
@@ -31,7 +44,8 @@ module MotionTab
|
|
31
44
|
tab[:badgeNumber] = 0 unless tab[:badgeNumber]
|
32
45
|
tab[:tag] = 0 unless tab[:tag]
|
33
46
|
|
34
|
-
viewController = tab[:viewController]
|
47
|
+
viewController = tab[:viewController]
|
48
|
+
viewController = tab[:viewController].alloc.init if tab[:viewController].respond_to?(:alloc)
|
35
49
|
|
36
50
|
if tab[:navigationController]
|
37
51
|
controller = UINavigationController.alloc.initWithRootViewController(viewController)
|
@@ -50,12 +64,25 @@ module MotionTab
|
|
50
64
|
title = tab[:title] if tab[:title]
|
51
65
|
|
52
66
|
tabBarItem = tabBarIcon(tab[:systemIcon], tab[:tag]) if tab[:systemIcon]
|
53
|
-
tabBarItem = tabBarIconCustom(title, tab[:icon]) if tab[:icon]
|
67
|
+
tabBarItem = tabBarIconCustom(title, tab[:icon], tab[:tag]) if tab[:icon]
|
54
68
|
|
55
69
|
tabBarItem.badgeValue = tab[:badgeNumber].to_s unless tab[:badgeNumber].nil? || tab[:badgeNumber] <= 0
|
56
70
|
|
57
71
|
return tabBarItem
|
58
72
|
end
|
73
|
+
|
74
|
+
def select(tabBarController, title: title)
|
75
|
+
tabBarController.viewControllers.each do |vc|
|
76
|
+
if vc.tabBarItem.title == title
|
77
|
+
tabBarController.selectedIndex = vc.tabBarItem.tag
|
78
|
+
return
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def select(tabBarController, tag: tag)
|
84
|
+
tabBarController.selectedIndex = tag
|
85
|
+
end
|
59
86
|
end
|
60
87
|
end
|
61
88
|
end
|
data/lib/motion-tab/version.rb
CHANGED