Class: RubyMotionQuery::Color
- Inherits:
-
UIColor
- Object
- UIColor
- RubyMotionQuery::Color
- Defined in:
- motion/ruby_motion_query/color.rb
Overview
Class Method Summary (collapse)
-
+ (UIColor) add_named(key, hex_or_color)
Add your own standard color.
-
+ (UIColor) from_hex(hex_color)
Creates a color from a hex triplet.
- + (UIColor) from_hsva(h, s, v, a)
- + (UIColor) from_rgba(r, g, b, a)
- + (Object) random
Class Method Details
+ (UIColor) add_named(key, hex_or_color)
Add your own standard color
77 78 79 80 81 82 83 84 85 86 87 |
# File 'motion/ruby_motion_query/color.rb', line 77 def add_named(key, hex_or_color) color = if hex_or_color.is_a?(String) Color.from_hex(hex_or_color) else hex_or_color end Color.define_singleton_method(key) do color end end |
+ (UIColor) from_hex(hex_color)
Creates a color from a hex triplet
Thanks bubblewrap for this method
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'motion/ruby_motion_query/color.rb', line 98 def from_hex(hex_color) hex_color = hex_color.gsub("#", "") case hex_color.size when 3 colors = hex_color.scan(%r{[0-9A-Fa-f]}).map{ |el| (el * 2).to_i(16) } when 6 colors = hex_color.scan(%r<[0-9A-Fa-f]{2}>).map{ |el| el.to_i(16) } else raise ArgumentError end if colors.size == 3 from_rgba(colors[0], colors[1], colors[2], 1.0) else raise ArgumentError end end |
+ (UIColor) from_hsva(h, s, v, a)
127 128 129 |
# File 'motion/ruby_motion_query/color.rb', line 127 def from_hsva(h,s,v,a) UIColor.alloc.initWithHue(h, saturation: s, brightness: v, alpha: a) end |
+ (UIColor) from_rgba(r, g, b, a)
119 120 121 |
# File 'motion/ruby_motion_query/color.rb', line 119 def from_rgba(r,g,b,a) UIColor.colorWithRed((r/255.0), green: (g/255.0), blue: (b/255.0), alpha: a) end |
+ (Object) random
131 132 133 |
# File 'motion/ruby_motion_query/color.rb', line 131 def random from_rgba(rand(255), rand(255), rand(255), 1.0) end |