tags:

views:

1319

answers:

3

i want to add an uiview for small size as a subview to existing view.

i have a uiviewcontroller pushed with a nib name which is the main view, i am trying to create an object of uiview and alloc it with dimension with the following code in the viewcontroller's viewdidload methoad

uiview *view = [[uiview alloc]];

but the ide is not suggesting the alloc on uiview and throwing an error if i forcefully type and run

please help me out with this

A: 
UIView *view = [[UIView alloc] init];
CVertex
`UIView *view = [[UIView alloc] init];`You missed a bracket.
marramgrass
thanks! type fail
CVertex
+1  A: 

UIView needs to be alloc'ed and init'ed with a frame:

CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *view = [[UIView alloc] initWithFrame:frame];
zaph
i am trying the same in viewdidload method of the of my viewcontroller class but the xcode is not suggesting alloc on uiview and if i forcefully copy paste this code the view if not being added as a subview to self.view
Gani
+3  A: 

To add something (rather 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 actually add it to the superview (assuming the view is self.view)

[self.view addSubview:view];
MiRAGe
i am trying the same in viewdidload method of the of my viewcontroller class but the xcode is not suggesting alloc on uiview and if i forcefully copy paste this code the view if not being added as a subview to self.view
Gani