gradient-view 0.1.1 → 0.1.2

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gradient-view (0.1.0)
4
+ gradient-view (0.1.1)
5
5
  rake
6
6
  sugarcube
7
7
 
@@ -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.size.width
34
- h = self.frame.size.height
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 = SugarCube::CoreGraphics::Point(w/2, h/2)
54
- start_point = center + SugarCube::CoreGraphics::Point(l * Math.cos(angle - Math::PI),
55
- l * Math.sin(angle - Math::PI))
56
- final_point = center + SugarCube::CoreGraphics::Point(l * Math.cos(angle),
57
- l * Math.sin(angle))
58
- gradient = CGGradientCreateWithColors(color_space, [the_start_color.uicolor.CGColor, the_final_color.uicolor.CGColor],
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
@@ -1,3 +1,3 @@
1
1
  class GradientView
2
- Version = '0.1.1'
2
+ Version = '0.1.2'
3
3
  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.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-09-29 00:00:00.000000000 Z
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake