motion-grid-overlay 1.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.
- checksums.yaml +7 -0
- data/README.md +40 -0
- data/lib/motion-grid-overlay.rb +8 -0
- data/lib/project/views/grid_overlay_view.rb +121 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8befc998959808f3b10409ea2c8b5503a05eb2ee
|
4
|
+
data.tar.gz: 4ec1aba20cd8216ac674fcef5a41de63efc9a6d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3ecb08f7885b9b06ead0c77234ee1709c41b467230a8d0900e8e116ee2aadd30b9106518839e05a8f88ecd7be0ba9faf25593380df0e076a6bab34e307bc282
|
7
|
+
data.tar.gz: 1c599fefe4234912949c82c7f542e137e4e6b0bd679ce1b7b44b0a7cb0602a460e8a4d5e258b1d18ba90d468b3c31e21d7f030d60aaa1343b61ebe340c4f1162
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# motion-grid-overlay
|
2
|
+
|
3
|
+
Simple grid overlay UIView subclass
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'motion-grid-overlay'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install motion-grid-overlay
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
grid_overlay = Motion::GridOverlayView.alloc.initWithFrame(target_view.bounds)
|
22
|
+
|
23
|
+
grid_overlay.x_lines = 3 # defaults to 2
|
24
|
+
grid_overlay.y_lines = 3 # defaults to 2
|
25
|
+
grid_overlay.stroke_color = UIColor.redColor # defaults to UIColor.grayColor
|
26
|
+
grid_overlay.stroke_width = 2.0 # defaults to 1.0
|
27
|
+
|
28
|
+
grid_overlay.hide
|
29
|
+
grid_overlay.show
|
30
|
+
grid_overlay.toggle
|
31
|
+
|
32
|
+
target_view.addSubview(grid_overlay)
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
@@ -0,0 +1,8 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise 'This file must be required within a RubyMotion project Rakefile.'
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, 'project/**/*.rb')))
|
8
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
class Motion
|
2
|
+
class GridOverlayView < UIView
|
3
|
+
DEFAULTS = { stroke_color: UIColor.grayColor,
|
4
|
+
stroke_width: 1.0,
|
5
|
+
x_lines: 2,
|
6
|
+
y_lines: 2 }
|
7
|
+
|
8
|
+
attr_accessor :x_interval, :y_interval
|
9
|
+
attr_reader :stroke_color, :stroke_width, :x_lines, :y_lines
|
10
|
+
|
11
|
+
def initWithFrame(frame)
|
12
|
+
super.tap do |view|
|
13
|
+
view.backgroundColor = UIColor.clearColor
|
14
|
+
|
15
|
+
self.x_lines = DEFAULTS[:x_lines]
|
16
|
+
self.y_lines = DEFAULTS[:y_lines]
|
17
|
+
self.stroke_color = DEFAULTS[:stroke_color]
|
18
|
+
self.stroke_width = DEFAULTS[:stroke_width]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def toggle
|
23
|
+
if hidden?
|
24
|
+
show
|
25
|
+
else
|
26
|
+
hide
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def show
|
31
|
+
self.stroke_color = @original_color
|
32
|
+
|
33
|
+
setNeedsDisplay
|
34
|
+
end
|
35
|
+
|
36
|
+
def hide
|
37
|
+
unless hidden?
|
38
|
+
@original_color = stroke_color
|
39
|
+
|
40
|
+
self.stroke_color = UIColor.clearColor
|
41
|
+
|
42
|
+
setNeedsDisplay
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def x_lines=(lines)
|
47
|
+
@x_lines = lines
|
48
|
+
self.y_interval = frame.size.height / (lines + 1)
|
49
|
+
|
50
|
+
setNeedsDisplay
|
51
|
+
end
|
52
|
+
|
53
|
+
def y_lines=(lines)
|
54
|
+
@y_lines = lines
|
55
|
+
self.x_interval = frame.size.width / (lines + 1)
|
56
|
+
|
57
|
+
setNeedsDisplay
|
58
|
+
end
|
59
|
+
|
60
|
+
def stroke_width=(width)
|
61
|
+
@stroke_width = width
|
62
|
+
|
63
|
+
setNeedsDisplay
|
64
|
+
end
|
65
|
+
|
66
|
+
def stroke_color=(color)
|
67
|
+
@stroke_color = color
|
68
|
+
|
69
|
+
setNeedsDisplay
|
70
|
+
end
|
71
|
+
|
72
|
+
def drawRect(rect)
|
73
|
+
super
|
74
|
+
|
75
|
+
setup_drawing
|
76
|
+
|
77
|
+
draw_horizontal_lines
|
78
|
+
draw_vertical_lines
|
79
|
+
|
80
|
+
fill_path
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def hidden?
|
86
|
+
stroke_color == UIColor.clearColor
|
87
|
+
end
|
88
|
+
|
89
|
+
def setup_drawing
|
90
|
+
CGContextSetStrokeColorWithColor(context, stroke_color.CGColor)
|
91
|
+
|
92
|
+
CGContextSetLineWidth(context, stroke_width)
|
93
|
+
end
|
94
|
+
|
95
|
+
def draw_horizontal_lines
|
96
|
+
(1..x_lines).each do |i|
|
97
|
+
draw_line([0, y_interval * i], [size.width, y_interval * i])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def draw_vertical_lines
|
102
|
+
(1..y_lines).each do |i|
|
103
|
+
draw_line([x_interval * i, 0], [x_interval * i, size.height])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def fill_path
|
108
|
+
CGContextStrokePath(context)
|
109
|
+
end
|
110
|
+
|
111
|
+
def draw_line(start_point, end_point)
|
112
|
+
CGContextMoveToPoint(context, start_point[0], start_point[1])
|
113
|
+
|
114
|
+
CGContextAddLineToPoint(context, end_point[0], end_point[1])
|
115
|
+
end
|
116
|
+
|
117
|
+
def context
|
118
|
+
@_context ||= UIGraphicsGetCurrentContext()
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-grid-overlay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Devon Blandin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Simple grid overlay UIView subclass
|
28
|
+
email:
|
29
|
+
- dblandin@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/motion-grid-overlay.rb
|
36
|
+
- lib/project/views/grid_overlay_view.rb
|
37
|
+
homepage: https://github.com/dblandin/motion-grid-overlay
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.0.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Simple grid overlay UIView subclass
|
61
|
+
test_files: []
|