How to implement loadView?

I created my own view called GraphView . All I get is a blank black screen when loading a view. Here is my code:

in GraphViewController.m:

 @synthesize graphView, graphModel; - (void)loadView { GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero]; self.view = aGraphView; self.graphView = aGraphView; [aGraphView release]; } 

I'm not sure why I just get a black screen when I try to implement loadView in GraphViewController.m

+4
source share
2 answers

I need to make the background color white in loadView

 - (void)loadView { GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero]; aGraphView.backgroundColor = [UIColor whiteColor]; self.view = aGraphView; self.graphView = aGraphView; [aGraphView release]; } 
+2
source

You do not set the frame for the GraphView object:

GraphView *aGraphView = [[GraphView alloc] init];

The designated initializer for the UIView is -initWithFrame: Do something like this (specifying the size / origin of the view as you wish):

GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

+2
source

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


All Articles