how can i create multiple view on a view
i have 2 classes with
- class view1.(from create project with view-base application the gray in background)
- class view2.(from add file uiviewcontroller subclass for view1,view2,view3 and view4)
in class view1 i create 4 uiview variable v1,v2,v3,v4 and link it to view 1,view 2, view 3 and view 4
in viewdidload of view1
i code
view2 *sub =[[view2 alloc] initWithNibName:@"view2" bundle:nil];
self.v1 = sub.view; (v1,v2,v3,v4 is view that i draw by interface开发者_如何转开发 builder on self.view)
but when run view2 that i create did not appear;
how can i make it appear.
view1 http://postimage.org/image/2mqhcxb1g/
view2 http://postimage.org/image/2mqj0gnj8/
thank you
right now you just assign that view to a variable, to make a view visible you should do the following:
[self.view addSubView:sub];
This will add the view to your current view and make it visible.
Following will appear in viewDidLoad: (for view2 only)
View2 *view2 = [[View2 alloc]
initWithNibName:@"View2" bundle:nil];
[self.view insertSubview:view2.view atIndex:0];
[view2 release];
[super viewDidLoad];
Try to give frame for this to set at desire position. And follow same for other 3 views...
EDIT
- (void)loadView
{
// Create the main view
CGRect appRect = [[UIScreen mainScreen] applicationFrame];
contentView = [[UIView alloc] initWithFrame:appRect];
contentView.backgroundColor = [UIColor whiteColor];
// Provide support for autorotation and resizing
contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view = contentView;
[contentView release];
// reset the origin point for subviews. The new origin is 0,0
appRect.origin = CGPointMake(0.0f, 0.0f);
// Add the subviews, each stepped by 32 pixels on each side
UIView *subview = [[UIView alloc] initWithFrame:CGRectInset(appRect, 32.0f, 32.0f)];
subview.backgroundColor = [UIColor lightGrayColor];
[contentView addSubview:subview];
[subview release];
subview = [[UIView alloc] initWithFrame:CGRectInset(appRect, 64.0f, 64.0f)];
subview.backgroundColor = [UIColor darkGrayColor];
[contentView addSubview:subview];
[subview release];
subview = [[UIView alloc] initWithFrame:CGRectInset(appRect, 96.0f, 96.0f)];
subview.backgroundColor = [UIColor blackColor];
[contentView addSubview:subview];
[subview release];
}
精彩评论