Skip to content

Instantly share code, notes, and snippets.

@dennislysenko
Created April 6, 2015 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennislysenko/f8e804eeec91df4f0c0c to your computer and use it in GitHub Desktop.
Save dennislysenko/f8e804eeec91df4f0c0c to your computer and use it in GitHub Desktop.
[UIViewController fubar] -- method to recursively color the view hierarchy
- (void)fubar
{
[self fubarWithViews:self.view.subviews];
}
- (void)fubarWithViews:(NSArray *)views
{
for (UIView *view in views) {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
[view setBackgroundColor:[color colorWithAlphaComponent:0.4]];
[self fubarWithViews:view.subviews];
}
}
@dennislysenko
Copy link
Author

Reference for generating a random color: https://gist.github.com/kylefox/1689973

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment