Class: Motion::Xray::XrayGradientView

Inherits:
UIView
  • Object
show all
Defined in:
lib/motion-xray/views/xray_gradient_view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from UIView

build_xray, #xray, #xray_subviews

Instance Attribute Details

#final_colorObject

Returns the value of attribute final_color.



5
6
7
# File 'lib/motion-xray/views/xray_gradient_view.rb', line 5

def final_color
  @final_color
end

#start_colorObject

Returns the value of attribute start_color.



4
5
6
# File 'lib/motion-xray/views/xray_gradient_view.rb', line 4

def start_color
  @start_color
end

Instance Method Details

#drawRect(rect) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/motion-xray/views/xray_gradient_view.rb', line 7

def drawRect(rect)
  context = UIGraphicsGetCurrentContext()
  color_space = CGColorSpaceCreateDeviceRGB()
  cgcolors = [
    (start_color || :white).uicolor.CGColor,
    (final_color || :light_gray).uicolor.CGColor,
  ]

  points = [0, 1]

  gradient = CGGradientCreateWithColors(color_space, cgcolors, points.to_pointer(:float))
  CGContextDrawLinearGradient(context, gradient, self.bounds.top_left, self.bounds.bottom_left, 0)
end