我無法弄清楚爲什麼這個視圖佔據了整個屏幕。UIView的大小不像預期的那樣是
在AppDelegate的文件
...
self.viewController = [[[ViewController alloc]init]autorelease];
[self.window setRootViewController:self.viewController];
self.window.backgroundColor = [UIColor whiteColor];
..
在ViewController.m
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 30, 30)];
[view setBackgroundColor:[UIColor greenColor]];
self.view = view;
當我運行應用程序的屏幕完全是綠色的,而不是隻有一個綠色的正方形。 這裏有什麼問題?
您在哪裏設置'self.view = view'? – 2012-02-18 14:22:51
我不明白你問什麼。 – OhDoh 2012-02-18 14:28:37
你在哪裏第二段代碼?在'loadView'方法中?但正如Richard J. Ross III所建議的,也許你需要使用(例如)'[self.window addSubview:view];' – 2012-02-18 14:33:20