Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to addSubview with a position?

I have something like this:

myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[mainCanvas addSubview: myViewController.view];
self.view = mainCanvas;

It will be added at the position (0, 0), but I want to add it at (0, 100) or somewhere else. How can I do so?

like image 987
DNB5brims Avatar asked Aug 19 '10 04:08

DNB5brims


3 Answers

Something like this:

myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil]; myViewController.view.frame = CGRectMake(0, 100, myViewController.view.frame.size.width, myViewController.view.frame.size.height);   [mainCanvas addSubview: myViewController.view]; self.view = mainCanvas; 
like image 102
acqu13sce Avatar answered Sep 22 '22 11:09

acqu13sce


In addition to setting the frame property, you can also set the center property of a view.

like image 44
Dave DeLong Avatar answered Sep 21 '22 11:09

Dave DeLong


Set the frame property on the sub view.

like image 35
Gary Avatar answered Sep 21 '22 11:09

Gary