How to add Subview using [self.view addSubview: myView], where myView is a subclass of UIView?

In my project, I have a custom @interface GraphView: UIView. Therefore, it GraphViewis a subclass UIViewand is intended to display a graph.

Then I create a new View Controller named Summaryusing NIB. In the interface builder, I just add UIToolbarat the bottom of the view.

In the implementation Summaryin the method viewDidLoad, I have the following code:

-(void)viewDidLoad {
  [super viewDidLoad];
  GraphView *myGraph = [[GraphView alloc]init];
  [self.view addSubview:myGraph]; //this does not work
}

But I can’t get it.

+3
source share
1 answer

, myGraph, self.

CGRect rect = CGRectInset(self.view.bounds, 0.0, 0.0);
GraphView *myGraph = [[GraphView alloc] initWithFrame:rect];
[self.view addSubview:myGraph];
+3

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


All Articles