Class: UIColor

Inherits:
Object
  • Object
show all
Defined in:
lib/project/uicolor.rb

Instance Method Summary collapse

Instance Method Details

#cgObject



106
107
108
# File 'lib/project/uicolor.rb', line 106

def cg
  self.CGColor
end

#darken(amount) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/project/uicolor.rb', line 41

def darken(amount)
  if components == 4
    color_values = hsb
    new_brightness = color_values[:brightness] - amount
    options = {brightness: new_brightness}
    adjust_hsb(options)
  else
    self.shade(amount)
  end
end

#desaturate(amount) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/project/uicolor.rb', line 65

def desaturate(amount)
  return self if components == 2
  color_values = hsb
  new_saturation = color_values[:saturation] - amount
  options = {saturation: new_saturation}
  adjust_hsb(options)
end

#grayscaleObject



11
12
13
# File 'lib/project/uicolor.rb', line 11

def grayscale
  get_grayscale
end

#grayscale?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/project/uicolor.rb', line 102

def grayscale?
  components == 2
end

#hsbObject



3
4
5
# File 'lib/project/uicolor.rb', line 3

def hsb
  get_hsb
end

#lighten(amount) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/project/uicolor.rb', line 15

def lighten(amount)
  if components == 4
    color_values = hsb
    new_brightness = color_values[:brightness] + amount
    options = {brightness: new_brightness}
    adjust_hsb(options)
  else
    self.tint(amount)
  end
end

#rgbObject



7
8
9
# File 'lib/project/uicolor.rb', line 7

def rgb
  get_rgb
end

#saturate(amount) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/project/uicolor.rb', line 73

def saturate(amount)
  return self if components == 2
  color_values = hsb
  new_saturation = color_values[:saturation] + amount
  options = {saturation: new_saturation}
  adjust_hsb(options)
end

#scale_darken(amount) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/project/uicolor.rb', line 52

def scale_darken(amount)
  if components == 4
    color_values = hsb
    new_brightness = color_values[:brightness] - (color_values[:brightness] * amount)
    options = {brightness: new_brightness}
    adjust_hsb(options)
  else
    color_values = grayscale
    new_brightness = color_values[:white] - (color_values[:white] * amount)
    UIColor.colorWithWhite(new_brightness, alpha:(color_values[:alpha]))
  end
end

#scale_lighten(amount) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/project/uicolor.rb', line 26

def scale_lighten(amount)
  if components == 4
    color_values = hsb
    diff = 1.0 - color_values[:brightness]
    new_brightness = color_values[:brightness] + (diff * amount)
    options = {brightness: new_brightness}
    adjust_hsb(options)
  else
    color_values = grayscale
    diff = 1.0 - color_values[:white]
    new_brightness = color_values[:white] + (diff * amount)
    UIColor.colorWithWhite(new_brightness, alpha:(color_values[:alpha]))
  end
end

#shade(amount) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/project/uicolor.rb', line 91

def shade(amount)
  if components == 4
    color_values = rgb
    UIColor.colorWithRed((color_values[:red] - amount), green:(color_values[:green] - amount), blue:(color_values[:blue] - amount), alpha:color_values[:alpha])
  else
    color_values = grayscale
    UIColor.colorWithWhite((color_values[:white] - amount), alpha:(color_values[:alpha]))
  end

end

#tint(amount) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/project/uicolor.rb', line 81

def tint(amount)
  if components == 4
    color_values = rgb
    UIColor.colorWithRed((color_values[:red] + amount), green:(color_values[:green] + amount), blue:(color_values[:blue] + amount), alpha:color_values[:alpha])
  else
    color_values = grayscale
    UIColor.colorWithWhite((color_values[:white] + amount), alpha:(color_values[:alpha]))
  end
end