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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}