gradient-view 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/gradient-view/gradient_view.rb +18 -11
- data/lib/gradient-view/version.rb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class GradientView < UIView
|
2
|
-
|
3
2
|
attr_accessor :startColor
|
4
3
|
attr_accessor :finalColor
|
5
4
|
attr_accessor :type # :linear, :radial
|
6
5
|
|
7
6
|
# for linear gradient:
|
8
|
-
attr_accessor :angle # 0 - PI
|
9
|
-
|
7
|
+
attr_accessor :angle # 0 - Math::PI
|
8
|
+
# for radial gradient:
|
9
|
+
attr_accessor :gradientCenter # CGPoint
|
10
10
|
|
11
11
|
def initWithFrame(frame)
|
12
12
|
super.tap do
|
@@ -14,6 +14,7 @@ class GradientView < UIView
|
|
14
14
|
self.finalColor = :black
|
15
15
|
self.angle = Math::PI / 2
|
16
16
|
self.type = :linear
|
17
|
+
self.backgroundColor = UIColor.clearColor
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -30,8 +31,8 @@ class GradientView < UIView
|
|
30
31
|
context = UIGraphicsGetCurrentContext()
|
31
32
|
color_space = CGColorSpaceCreateDeviceRGB()
|
32
33
|
|
33
|
-
w = self.frame
|
34
|
-
h = self.frame
|
34
|
+
w = CGRectGetWidth(self.frame)
|
35
|
+
h = CGRectGetWidth(self.frame)
|
35
36
|
if w == 0 or h == 0
|
36
37
|
return
|
37
38
|
end
|
@@ -50,12 +51,18 @@ class GradientView < UIView
|
|
50
51
|
inner_angle = self.angle - r_angle
|
51
52
|
l = radius * Math.cos(inner_angle)
|
52
53
|
|
53
|
-
center =
|
54
|
-
start_point = center +
|
55
|
-
|
56
|
-
final_point = center +
|
57
|
-
|
58
|
-
|
54
|
+
center = CGPoint.new(w/2, h/2)
|
55
|
+
start_point = center + CGPoint.new(l * Math.cos(angle - Math::PI),
|
56
|
+
l * Math.sin(angle - Math::PI))
|
57
|
+
final_point = center + CGPoint.new(l * Math.cos(angle),
|
58
|
+
l * Math.sin(angle))
|
59
|
+
start_color = self.startColor
|
60
|
+
start_color = start_color.uicolor unless start_color.is_a? UIColor
|
61
|
+
|
62
|
+
final_color = self.finalColor
|
63
|
+
final_color = final_color.uicolor unless final_color.is_a? UIColor
|
64
|
+
|
65
|
+
gradient = CGGradientCreateWithColors(color_space, [start_color.CGColor, final_color.CGColor],
|
59
66
|
[0, 1].to_pointer(:float))
|
60
67
|
CGContextDrawLinearGradient(context, gradient, start_point, final_point, 0)
|
61
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gradient-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|