Creating uiview software?

Create a view with the 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 filling the entire screen with yellow, but I want with the specified frame. I create this view in a view based application. Am I doing something wrong, Overrideind the original view?

+6
source share
4 answers

You can do it as follows.

  - (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]; }; 
+20
source

replace self.view =paintView; by

 [self.view addSubview: paintView]; 
0
source

I am going to change line number 3 in the LoadView method, you should add a subView in the main view, and not with the immediate answer.

 [self.view addSubview:paintview]; 
0
source
 UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,35)]; newView.backgroundColor=[UIColor clearColor]; UITextView *mytext = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 0.0, 100.0, 28.0)]; mytext.backgroundColor = [UIColor clearColor]; mytext.textColor = [UIColor blackColor]; mytext.editable = NO; mytext.font = [UIFont systemFontOfSize:15]; mytext.text = @"Mytext"; mytext.scrollEnabled=NO; [mytext release]; [newView addSubview:mytext]; [self.view addSubview:newView]; 
0
source

Source: https://habr.com/ru/post/904232/


All Articles