{"id":158,"date":"2013-12-17T22:47:41","date_gmt":"2013-12-18T04:47:41","guid":{"rendered":"http:\/\/dev.iachieved.it\/iachievedit\/?p=158"},"modified":"2018-12-23T17:33:37","modified_gmt":"2018-12-23T23:33:37","slug":"uicolor-colorwithredgreenblue","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/uicolor-colorwithredgreenblue\/","title":{"rendered":"[UIColor colorWithRed:green:blue]"},"content":{"rendered":"<p>If you&#8217;ve done web development and needed to add that perfect splash of color, you&#8217;ve come to appreciate websites like <a href=\"http:\/\/www.color-hex.com\/\">Color Hex<\/a> or <a href=\"http:\/\/www.w3schools.com\/html\/html_colornames.asp\">W3Schools<\/a> for grabbing an HTML code like #8A2BE2 (it&#8217;s blue violet if you were curious) or an RGB code like 138,43,226 (it&#8217;s blue violet too).  Or, perhaps you&#8217;ve used <a href=\"http:\/\/en.wikipedia.org\/wiki\/DigitalColor_Meter\">DigitalColor Meter<\/a> on the Mac or something equivalent for Windows.  What you probably <em>haven&#8217;t<\/em> seen is a tool that displays the color code in the format that for some inexplicable reason Apple chose to use with <code>UIColor<\/code>.  Per the <a href=\"https:\/\/developer.apple.com\/library\/IOS\/documentation\/UIKit\/Reference\/UIColor_Class\/Reference\/Reference.html\">UIColor Class Reference<\/a>, if I wanted to use blue violet, I would need to code up<\/p>\n<p>[objc]<br \/>\nUIColor* blueViolet = [UIColor colorWithRed:0.541176<br \/>\n                                      green:0.168627<br \/>\n                                       blue:0.886275 alpha:1.0];<br \/>\n[\/objc]<\/p>\n<p>From the <code>UIColor<\/code> class reference, the first parameter (what you give to <code>colorWithRed:<\/code>) should be &#8220;The red component of the color object, specified as a value from 0.0 to 1.0.&#8221;  Hmm&#8230; I&#8217;ve always seen red given as hexadecimal or decimal, but never as a &#8220;value between 0.0 to 1.0&#8221;  So what ends up happening is I find the color I want (usually with the DigitalColor Meter tool), pull out a calculator, and type in the R value, divide by 255, and then repeat for G and B.  And here we thought computers were supposed to make our lives easier.  Or better, if someone gives me a hexadecimal code, I convert to base 10 and then divide by 255.<\/p>\n<p>This is all a bit too annoying, so we present our own <a href=\"https:\/\/dev.iachieved.it\/uicolorpicker.html\">UIColor Picker<\/a>.  You know how to use this tool&#8230; it&#8217;s pretty straightforward.  Find the color you want, copy and paste the code.  Done.  Going for that teal (#008080) look?  Type it in and you&#8217;re done<\/p>\n<p>[objc]<br \/>\nUIColor* teal =[UIColor colorWithRed:0.00000<br \/>\n                               green:0.501961<br \/>\n                                blue:0.501961 alpha:1.0];<br \/>\n[\/objc]<\/p>\n<p>As a bonus, you can slide the opacity bar to select an alpha channel value.  The possibilities are endless.  Well, okay, the possibilities are finite but you get the idea.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve done web development and needed to add that perfect splash of color, you&#8217;ve come to appreciate websites like Color Hex or W3Schools for grabbing an HTML code like #8A2BE2 (it&#8217;s blue violet if you were curious) or an RGB code like 138,43,226 (it&#8217;s blue violet too). Or, perhaps you&#8217;ve used DigitalColor Meter on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-xcodetips"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/158"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":3,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":3622,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/158\/revisions\/3622"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}