simple-view 0.1.0 → 0.1.1
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 +79 -31
- data/lib/simple_view/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SimpleView
|
2
2
|
|
3
|
-
|
3
|
+
RubyMotion DSL for UIKit.
|
4
4
|
|
5
5
|
Demo app: [Currency](https://github.com/seanho/CurrencyApp-RubyMotion)
|
6
6
|
|
@@ -8,7 +8,7 @@ Demo app: [Currency](https://github.com/seanho/CurrencyApp-RubyMotion)
|
|
8
8
|
|
9
9
|
Add the gem to your Gemfile
|
10
10
|
|
11
|
-
`gem 'simple-view'
|
11
|
+
`gem 'simple-view'`
|
12
12
|
|
13
13
|
Then `bundle install`
|
14
14
|
|
@@ -28,30 +28,44 @@ end
|
|
28
28
|
## Usage
|
29
29
|
|
30
30
|
````ruby
|
31
|
-
|
32
|
-
SimpleView::
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
class YourViewController < UIViewController
|
32
|
+
include SimpleView::Layout
|
33
|
+
|
34
|
+
def viewDidLoad
|
35
|
+
setup content_view do
|
36
|
+
label width: 200, height: 20, text: "Choose your lucky word", color: "#eee"
|
37
|
+
image_view top: 50, left: 50, right: 50, image: "sample.jpg"
|
38
|
+
toolbar anchors: [:bottom]
|
39
|
+
end
|
36
40
|
end
|
37
41
|
end
|
38
42
|
````
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
Hash parameters works only on KVC-compliant properties. To configure view object in more detail, use a block
|
44
|
+
Use block for more control over the view instance
|
43
45
|
|
44
46
|
````ruby
|
45
47
|
def viewDidLoad
|
46
|
-
|
47
|
-
button do
|
48
|
-
|
48
|
+
setup view do
|
49
|
+
button tint_color: '#f00' do
|
50
|
+
view.setTitle "Submit" forState: UIControlStateNormal
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
````
|
53
55
|
|
54
56
|
### UIKit support
|
57
|
+
|
58
|
+
SimpleView provides shorthand methods for most UIKit classes
|
59
|
+
|
60
|
+
````ruby
|
61
|
+
def viewDidLoad
|
62
|
+
setup view do
|
63
|
+
label text: 'Hi there!' # shorthand
|
64
|
+
add UILabel, text: 'Hi there!' # what actually happens
|
65
|
+
end
|
66
|
+
end
|
67
|
+
````
|
68
|
+
|
55
69
|
- UIActivityIndicatorView via `activity_indicator`
|
56
70
|
- UIButton via `button`
|
57
71
|
- UIDatePicker via `date_picker`
|
@@ -77,72 +91,106 @@ end
|
|
77
91
|
|
78
92
|
### Custom view support
|
79
93
|
|
80
|
-
SimpleView
|
94
|
+
SimpleView can work with any custom views and controls
|
81
95
|
|
82
96
|
````ruby
|
83
|
-
|
97
|
+
setup view do
|
84
98
|
add CustomViewClass, name: "custom_view"...
|
85
99
|
end
|
86
100
|
````
|
87
101
|
|
88
102
|
### Style Template
|
89
103
|
|
90
|
-
|
91
|
-
|
92
|
-
Define a style and apply to multiple views with ease.
|
104
|
+
Define default style and apply to UI classes automatically
|
93
105
|
|
94
106
|
````ruby
|
95
107
|
class AppDelegate
|
96
108
|
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
97
|
-
SimpleView::Styles.define
|
109
|
+
SimpleView::Styles.define UILabel,
|
98
110
|
font: "italic 13",
|
99
111
|
text_color: "#999"
|
100
112
|
end
|
101
113
|
end
|
102
114
|
|
103
115
|
class ViewController
|
116
|
+
include SimpleView::Layout
|
117
|
+
|
104
118
|
def viewDidLoad
|
105
|
-
|
106
|
-
label
|
107
|
-
label styles: :tag_label, text: "Right", anchors: [:right]
|
119
|
+
setup view do
|
120
|
+
label text: "Label with default style!"
|
108
121
|
end
|
109
122
|
end
|
110
123
|
end
|
111
124
|
````
|
112
125
|
|
126
|
+
Define custom styles and mix with default style
|
127
|
+
|
128
|
+
````ruby
|
129
|
+
class AppDelegate
|
130
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
131
|
+
SimpleView::Styles.define UILabel,
|
132
|
+
font: "13"
|
133
|
+
|
134
|
+
SimpleView::Styles.define :darkcolor,
|
135
|
+
text_color: "#999"
|
136
|
+
|
137
|
+
SimpleView::Styles.define :title,
|
138
|
+
font: "bold 15"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class ViewController
|
143
|
+
include SimpleView::Layout
|
144
|
+
|
145
|
+
def viewDidLoad
|
146
|
+
setup view do
|
147
|
+
label styles: :darkcolor, text: "13 font with dark color"
|
148
|
+
label styles: [:darkcolor, :title], text: "bold 15 font with dark color"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
````
|
113
153
|
|
114
154
|
### View anchoring
|
115
155
|
|
156
|
+
Position the view without doing a lot of calculation
|
157
|
+
|
116
158
|
````ruby
|
117
|
-
|
159
|
+
setup view do
|
118
160
|
toolbar bottom: 10, left: 10, right: 10, anchors: [:bottom]
|
119
161
|
end
|
120
162
|
````
|
121
163
|
|
122
164
|
### Passing in locals
|
123
165
|
|
124
|
-
|
166
|
+
Reference to the controller/model or other variables in the setup block
|
125
167
|
|
126
168
|
````ruby
|
127
|
-
|
128
|
-
SimpleView::
|
129
|
-
|
169
|
+
class ViewController
|
170
|
+
include SimpleView::Layout
|
171
|
+
|
172
|
+
def viewDidLoad
|
173
|
+
setup view, controller: self do
|
174
|
+
table_view delegate: controller, dataSource: controller
|
175
|
+
end
|
130
176
|
end
|
131
177
|
end
|
132
178
|
````
|
133
179
|
|
134
180
|
### View tagging with string
|
135
181
|
|
136
|
-
|
182
|
+
Tag view with name string and find them with ease
|
137
183
|
|
138
184
|
````ruby
|
139
185
|
def viewDidLoad
|
140
|
-
|
141
|
-
label name:
|
186
|
+
setup view do
|
187
|
+
label name: 'desc'
|
188
|
+
label name: 'price'
|
142
189
|
end
|
143
190
|
end
|
144
191
|
|
145
192
|
def someOtherMethod
|
146
|
-
view.
|
193
|
+
price_label = view.find('price')
|
194
|
+
desc_label = price_label.sibling('desc')
|
147
195
|
end
|
148
196
|
````
|
data/lib/simple_view/version.rb
CHANGED