I want to add an additional view in the current view, this additional view is 300x300. When I add subview using
[self.view addSubview:md.view];
md.view will appear at position (0,0), is there a way to add subview to the center?
thanks
You can set the center view:
center
md.view.center = self.view.center;
Or you can explicitly set the frame for md.view so that it is centered as you wish.
Using
CGRect bounds = self.view.bounds; md.view.center = CGPointMake(bounds.size.width / 2, bounds.size.height / 2);
before or after this line -addSubview:
-addSubview:
You can specify exactly where you want the view to be placed in the parent view by doing this in the viewDidLoad method as follows:
- (void)viewDidLoad { [super viewDidLoad]; SubView1Controller *subView1Controller=[[[SubView1Controller alloc] initWithNibName:@"SubView1" bundle:nil] autorelease]; CGRect r = [subView1Controller.view frame]; r.origin.x = 50; r.origin.y = 50; [subView1Controller.view setFrame:r]; [self.view insertSubview:subView1Controller.view atIndex:0]; }
Source: https://habr.com/ru/post/1312181/More articles:Math annotations in PDF file - annotationsWhy are my aspx pages not cached on the client? - httpHow to insert a source PDF file into an existing PDF page? - pdfHow to explain CSS Float in a common language? - cssEclipse: finding a resource on the way to classes - javaHow do I make fun of the IP address in cucumbers / capybara? - ruby-on-railsHibernate - limitation for a class in a list - sqlWPF Image Viewer Application Examples - c #Delete EJB bean state in client - javacurl does not work in xampp localhost - curlAll Articles