views:

553

answers:

2

I created a label using Interface Builder, and now I want to set the background color of the label using code instead of IB's color picker. (I want to do this so that I can define the color using RGB and eventually change the colorspace for the label.)

I'm in cocoa. How do I edit the attributes of an IB object using code?

My code looks like this:

//.h file

#import <UIKit/UIKit.h>

@interface IBAppDelegate : NSObject {

    UILabel  *label;
}

@property (nonatomic, retain) IBOutlet UILabel *label;

@end



//.m file


#import "IBAppDelegate.h"

@implementation IBAppDelegate

@synthesize label;

(memory stuff...)

@end
+2  A: 

label.backgroundColor = [UIColor greenColor]

There's nothing special about the objects in your XIB file. They're just normal objects.

Terry Wilcox
+2  A: 
- (void)applicationDidBecomeActive:(UIApplication*)application
{
    self.label.backgroundColor = [UIColor colorWithRed:0.1f
                                                 green:0.2f
                                                  blue:0.3f
                                                 alpha:1.0f];
}
Nikolai Ruhe
Thank you so much!!! I knew it had to be something simple. I looked everywhere and couldn't find a straight answer.
Evelyn
You are very welcome.
Nikolai Ruhe