如何将视图控制器背景颜色从灰色更改为设置颜色?

时间:2012-09-24 23:33:53

标签: objective-c xcode

我正在尝试更改viewcontroller的颜色。

有人让我知道如下。

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

}

这是AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[[ViewController alloc] init] autorelease];
    } else {
        self.viewController = [[[ViewController alloc] init] autorelease];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

这是ViewController.m

#import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

但是,结果是viewcontroller是黑屏。

如何更改设置backgroundcolor?

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个

self.view.backgroundColor = [UIColor clearColor];