Class: UIColor

Inherits:
Object
  • Object
show all
Defined in:
lib/purplish-red/non-ui/ui_color.rb

Instance Method Summary collapse

Instance Method Details

#alphaObject



39
40
41
42
43
44
45
# File 'lib/purplish-red/non-ui/ui_color.rb', line 39

def alpha
  if grayscale_colorspace?
    components[1]
  else
    components[3]
  end
end

#blueObject



34
35
36
# File 'lib/purplish-red/non-ui/ui_color.rb', line 34

def blue
  (components[2]*255).round
end

#color_with_alpha(a) ⇒ Object



53
54
55
56
# File 'lib/purplish-red/non-ui/ui_color.rb', line 53

def color_with_alpha(a)
  comps = components
  UIColor.alloc.initWithRed(comps[0], green:comps[1], blue:comps[2], alpha:a)
end

#componentsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/purplish-red/non-ui/ui_color.rb', line 7

def components
  if grayscale_colorspace?
    white = Pointer.new(:float)
    alpha = Pointer.new(:float)
    self.getWhite(white, alpha:alpha)
    [white[0], alpha[0]]
  else
    red = Pointer.new(:float)
    green = Pointer.new(:float)
    blue = Pointer.new(:float)
    alpha = Pointer.new(:float)
    self.getRed(red, green:green, blue:blue, alpha:alpha)
    [red[0], green[0], blue[0], alpha[0]]
  end
end

#grayscale_colorspace?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/purplish-red/non-ui/ui_color.rb', line 2

def grayscale_colorspace?
  CGColorGetNumberOfComponents(self.CGColor) == 2
end

#greenObject



29
30
31
# File 'lib/purplish-red/non-ui/ui_color.rb', line 29

def green
  (components[1]*255).round
end

#redObject



24
25
26
# File 'lib/purplish-red/non-ui/ui_color.rb', line 24

def red
  (components[0]*255).round
end

#whiteObject



48
49
50
# File 'lib/purplish-red/non-ui/ui_color.rb', line 48

def white
  components[0]
end