Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating uiview programmatically?

Tags:

ios

uiview

Creating a view with following code.

  - (void)loadView {

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

But my problem is whole screen fills with yellow color, but I want with specified frame. I am creating this view in a view based application.. Am i doing something wrong, Overridind the original view?

like image 632
NoviceDeveloper Avatar asked Dec 21 '11 10:12

NoviceDeveloper


1 Answers

You can do it in following way.

  - (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];
  };
like image 178
AechoLiu Avatar answered Oct 01 '22 02:10

AechoLiu