I have a main controller header with a color declaration
MainViewController.h
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
UIColor *myColor;
}
@property (nonatomic, retain) UIColor *myColor;
@end
and an implementation with an initialization
MainViewController.m
@implementation MainViewController
@synthesize myColor;
- (void)viewDidLoad
{
[super viewDidLoad];
myColor = [UIColor colorWithRed:1.0 green:0.98 blue:0.8 alpha:1]; //initialization
}
Now I want to use this color in a method in MainViewController like this
- (void) myMethod {
myTextField.backgroundColor = myColor;
}
but but all my attempts are in vain. What is the correct syntax?
You must send a retain to the color object you initialize :
or set the property like so :
which, according to the property you declared, should retain it. The way you set the
backgroundColoris ok.