DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Convert RGB Values Into RGB Value For CocoaTouch UIColor

01.11.2009
| 17589 views |
  • submit to reddit
        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