0

I want to change the background color of my label with a variable how can I do that ?

This is my code but I'd like to have a variable instead of 'redColor'

[publisherLabel setBackgroundColor:[UIColor redColor]];
Justin Boo
  • 10,132
  • 8
  • 50
  • 71
Ezix
  • 126
  • 1
  • 8
  • 1
    [UIColor redColor] returns a UIColor object, so you can keep a reference to it like `UIColor *red = [UIColor redColor]` and pass that to `setBackgroundColor:`, is that what you mean? – Rob Lourens Apr 05 '12 at 16:33

1 Answers1

3

Variable with color from an RGBA value.

UIColor *myColor = [UIColor colorWithRed:100.0/255.0 green:101.0/255.0 blue:102.0/255.0 alpha:1.0]];

You can also use HEX if you want:

#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 
 green:((c>>16)&0xFF)/255.0 
 blue:((c>>8)&0xFF)/255.0 
 alpha:((c)&0xFF)/255.0];

// usage:
UIColor* c = HEXCOLOR(0xff00ffff);