Over a million developers have joined DZone.

Convert RGB Values Into RGB Value For CocoaTouch UIColor

·
For some reason it's a bit misleading thinking UIColor would use RGB values not in floats
so after some thinking I wrote ruby script to quickly get the RGB values into something 
UITouch can use.



 UITableView * tbview = [[UITableView alloc] init];
 [tbview setBackgroundColor:[UIColor colorWithRed:0.796078431372549 
                                                  green:0.866666666666667 
                                                   blue:0.917647058823529 
                                                  alpha:1.0]];





#!/usr/bin/env ruby

def convert_color(val)
  (1.0 * val) / 255
end

# hex color is #C4D6E4

puts convert_color(203) # RED
puts convert_color(221) # GREEN
puts convert_color(234) # BLUE

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}