无法更改UIView背景颜色和UILabel文本颜色iOS 8

时间:2014-11-26 19:22:52

标签: ios objective-c uiview uilabel

我看了很多帖子,似乎没有人帮我解决当前遇到的问题。我试图通过按钮单击以编程方式更改UIView背景颜色和UILabel文本颜色。它们都在界面构建器中连接。我所做的是打开Main.storyboard旁边的ViewController.h文件,然后单击并拖动以连接视图(backgroundView)和标签(letterR)。

如果有人能够看到我做错了什么,那将非常感谢!

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

0 个答案:

没有答案