3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'motion-prime/helpers/has_styles.rb', line 3
def prepare_gradient(options)
colors = options[:colors].map(&:uicolor).map(&:cgcolor)
locations = options[:locations] if options[:locations]
if self.is_a?(ViewStyler)
gradient = CAGradientLayer.layer
gradient.frame = if options[:frame_width]
CGRectMake(options[:frame_x].to_f, options[:frame_y].to_f, options[:frame_width].to_f, options[:frame_height].to_f)
else
options[:parent_frame] || CGRectZero
end
gradient.colors = colors
gradient.locations = locations
else
color_space = CGColorSpaceCreateDeviceRGB()
locations_pointer = Pointer.new(:float, 2)
locations.each_with_index { |loc, id| locations_pointer[id] = loc }
gradient = CGGradientCreateWithColors(color_space, colors, locations_pointer)
end
gradient
end
|