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.
Files changed (3) hide show
  1. data/README.md +79 -31
  2. data/lib/simple_view/version.rb +1 -1
  3. metadata +1 -1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SimpleView
2
2
 
3
- A DSL for UIKit for RubyMotion.
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', :git => 'https://github.com/seanho/SimpleView.git'`
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
- def viewDidLoad
32
- SimpleView::Layouts.setup(view) do
33
- label width: 200, height: 20, text: "Choose your lucky word", color: "#eee"
34
- image_view top: 50, left: 50, right: 50, image: "sample.jpg"
35
- toolbar anchors: [:bottom]
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
- Everything inside setup block will be added to the view automatically.
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
- SimpleView::Layouts.setup(view) do
47
- button do
48
- @view.setTitle("Submit" forState: UIControlStateNormal)
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 works not only with UIKit, custom or 3rd party created views and controls can also be used
94
+ SimpleView can work with any custom views and controls
81
95
 
82
96
  ````ruby
83
- SimpleView::Layouts.setup(view) do
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
- _Experimental. Might change in future._
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 :tag_label,
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
- SimpleView::Layouts.setup(view, controller: self) do
106
- label styles: :tag_label, text: "Left", anchors: [:left]
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
- SimpleView::Layouts.setup(view) do
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
- Hash parameters will automatically turns into instance variable within the block
166
+ Reference to the controller/model or other variables in the setup block
125
167
 
126
168
  ````ruby
127
- def viewDidLoad
128
- SimpleView::Layouts.setup(view, controller: self) do
129
- table_view delegate: @controller, dataSource: @controller
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
- No need to declare ivar, no need to use integer tag, just name your view and access it by the name.
182
+ Tag view with name string and find them with ease
137
183
 
138
184
  ````ruby
139
185
  def viewDidLoad
140
- SimpleView::Layouts.setup(view) do
141
- label name: "price_label" # give a name to the label
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.subview("price_label") # get the label
193
+ price_label = view.find('price')
194
+ desc_label = price_label.sibling('desc')
147
195
  end
148
196
  ````
@@ -1,3 +1,3 @@
1
1
  module SimpleView
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: