Nerdatope
Nerdatope

Reputation: 127

How can I change a UILabel's text color back to what it was when the program first launched in Xcode for iOS 7?

When programming in Obj-C for iPhone, it is often necessary to adjust the text color of objects such as labels, buttons, etc. I get that we usually do this by using code like:

 myLable.textColor = [UIColor redColor];

Now my problems arise when the color I started with is not one of the pre-defined UIColors. I can change its text's color to any of the pre-defined (as in this case, red), but how can I revert the color to the one I chose in the storyboard (the color of the label's text as the program first starts)?

Thanks in advance for your help!

Upvotes: 0

Views: 1952

Answers (1)

klcjr89
klcjr89

Reputation: 5902

As my comment suggests, you should create a property to later access your custom color like this:

@property (nonatomic, strong) UIColor *myColor; 

- (void)viewDidLoad
{
    // Set the values as the ones in storyboard. Make sure to always divide by 255.0!
    self.myColor = [UIColor colorWithRed:(255.0/255.0) green:(59.0/255.0) blue:(48.0/255.0) alpha:1.0];
    // Set the label's text color property to our custom color.
    myLabel.textColor = self.myColor;
}

In storyboard, click here to find the exact color you need:

enter image description here

Upvotes: 1

Related Questions