Adding uiview as a subordinate main view

I want to add UIViewfor a small size as a subview of an existing view.

I have UIViewControllerclicked with the name nib, which is the main view, I am trying to create an object UIViewand distribute it using a measurement using the following code in viewcontroller viewDidLoadmethoad

UIView *view = [[UIView alloc] init];

but the idea does not involve highlighting on UIViewand throws an error if I force-type and run

please help me with this

+5
source share
3 answers

To add something (very important) to the answers above;

CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *view = [[UIView alloc] initWithFrame:frame];

Then you want to add it to the supervisor (assuming view is self.view)

[self.view addSubview:view];
+11

UIView init'ed :

CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *view = [[UIView alloc] initWithFrame:frame];
+3
UIView *view = [[UIView alloc] init];
0
source

All Articles