{"id":1559,"date":"2013-12-22T11:11:20","date_gmt":"2013-12-22T19:11:20","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1559"},"modified":"2013-12-22T11:11:20","modified_gmt":"2013-12-22T19:11:20","slug":"pick-a-random-color-in-ios","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1559","title":{"rendered":"Pick a random color in iOS"},"content":{"rendered":"<p>In one of my methods I wanted to put randomly colored text on the screen. I put this class method in my Utilities.m class.<\/p>\n<p><pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\n#define ARC4RANDOM_MAX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x100000000\n+ (UIColor *) randomColor {\n&nbsp;&nbsp;&nbsp;&nbsp;CGFloat red =&nbsp;&nbsp;(CGFloat)arc4random()\/ARC4RANDOM_MAX;\n&nbsp;&nbsp;&nbsp;&nbsp;CGFloat blue = (CGFloat)arc4random()\/ARC4RANDOM_MAX;\n&nbsp;&nbsp;&nbsp;&nbsp;CGFloat green = (CGFloat)arc4random()\/ARC4RANDOM_MAX;\n&nbsp;&nbsp;&nbsp;&nbsp;return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];\n}\n<\/code><\/pre><\/p>\n<p>To set the color, just call<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\nlabel.textColor = [Utilities randomColor];\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my methods I wanted to put randomly colored text on the screen. I put this class method in my Utilities.m class. #define ARC4RANDOM_MAX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x100000000 + (UIColor *) randomColor { &nbsp;&nbsp;&nbsp;&nbsp;CGFloat red =&nbsp;&nbsp;(CGFloat)arc4random()\/ARC4RANDOM_MAX; &nbsp;&nbsp;&nbsp;&nbsp;CGFloat blue = (CGFloat)arc4random()\/ARC4RANDOM_MAX; &nbsp;&nbsp;&nbsp;&nbsp;CGFloat green = (CGFloat)arc4random()\/ARC4RANDOM_MAX; &nbsp;&nbsp;&nbsp;&nbsp;return [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; } To set the color, just call &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1559\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Pick a random color in iOS<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1559","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1559"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1559\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}