xCode 4.3 how to programmatically access interface builder palette colors?
Asked Answered
S

1

7

I'm building the interface within interface builder and see that there's a variety of color palettes available for selecting font and background colors:

background color>other>color widget 3rd tab > Palette

Some of them have weird names like "Ice", "Sky", etc.

From my code I have access to

[UIColor blueColor];
[UIColor cyanColor];

Is there a way for me to access these additional colors by name from my code? For example,

//Is there a method call that does something like this?
[Color colorNamed:@"Ice" inPalette:@"Apple"];

Thank you!

Sandra answered 13/6, 2012 at 14:42 Comment(0)
A
9

You would need to get the RGB values of the colors you need from the crayon colors. You could access them that way, "Sky" would be: [UIColor colorWithRed:(102.0/255.0) green:(204.0/255.0) blue:(255.0/255.0) alpha:1.0];

Or add UIColor categories that add all of the colors you need: [UIColor skyColor];

In UIColor+Colors.h add:

@interface UIColor (Colors)
+(UIColor *)skyColor;
@end

In UIColor+Colors.m add:

@implementation UIColor (Colors)
+(UIColor *)skyColor
{
  static UIColor *color = nil;
  if (!color)
    color = [[UIColor alloc] initWithRed:(102.0/255.0) green:(204.0/255.0) blue:(255.0/255.0) alpha:1.0];
  return color;
}
@end
Audacity answered 13/6, 2012 at 15:3 Comment(3)
Thank you for the recommendation. I'm specifically trying to avoid having to think of the RGB values and instead simply picking from a pre-defined palette names.Sandra
You don't have to "think" of the values. If you want them from the predefined crayons, open the colors pane, select the crayon tab and the crayon you want, then select the RGB tab and that crayon's RGB values is defined for you.Audacity
Here, someone already did all of the legwork for the categories: github.com/rob-brown/RBCategories/blob/master/…Audacity

© 2022 - 2024 — McMap. All rights reserved.