ios – 以编程方式创建uiview?

使用以下代码创建视图.

  - (void)loadView {

paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
[paintView setBackgroundColor:[UIColor yellowColor]];
self.view = paintView;
[paintView release];

但我的问题是整个屏幕填充黄色,但我想要指定的框架.
我在基于视图的应用程序中创建此视图..我做错了什么,Overridind原始视图?

最佳答案
你可以通过以下方式完成.

  - (void)loadView {
    /// make a empty view to self.view 
    /// after calling [super loadView], self.view won't be nil anymore. 
    [super loadView]; 

    paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
    [paintView setBackgroundColor:[UIColor yellowColor]];
    [self.view addSubview:paintView];
    [paintView release];
  };

转载注明原文:ios – 以编程方式创建uiview? - 代码日志