dimanche 30 novembre 2014

Cannot change UIView background color and UILabel text color in iOS 8

I've looked at many posts and none seem to help with the current issue I'm experiencing. I am trying to change the UIView background color and UILabel text color programmatically on a button click. They are all connected in the interface builder. What I did was open the ViewController.h file next to the Main.storyboard and clicked and dragged to connect the view (backgroundView) and label (letterR).


If anyone can see what I am doing wrong that would be great thanks!


ViewController.h



#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{

IBOutlet UIView *backgroundView;
IBOutlet UILabel *letterR;
}

@end


ViewController.m



#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

static int flag = 0;

- (void)viewDidLoad {
[super viewDidLoad];
}

- (IBAction)ButtonClick:(id)sender {

if(flag == 0){

flag = 1;
letterR.textColor = [UIColor blackColor];
backgroundView.backgroundColor = [UIColor whiteColor];
}

else if(flag == 1){

flag = 0;
letterR.textColor = [UIColor whiteColor];
backgroundView.backgroundColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:1];
}
}

@end


When monitoring the NSLog output of the label and background this is what I am getting:


Letter R: 2014-11-26 15:18:18.358 Rave[3923:340203] Letter R: >


Printing the color of the letter:(null)


Background: 2014-11-26 15:18:18.358 Rave[3923:340203] Background: >


Printing the color of the background:2014-11-26 15:23:13.467 Rave[3962:342332] Background Color: UIDeviceRGBColorSpace 0 1 1 1


Also the background color is being modified just not updated on screen of the simulator.




Aucun commentaire:

Enregistrer un commentaire