- (void)viewDidLoad
{
[super viewDidLoad];
UITabBarController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"tabbar"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0,0, 500, 500);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
}
How can I add tabbar viewcontroller as child view to uiviewcontroller in objective-C?
As already mentioned your already doing it here [self.view addSubview:controller.view]
The autoresizing mask of the view of the tabbar controller assumes the full size of its superview.
If you set the frame when instantiating the tabbar controller, be sure to change the autoresizingMask
property of the tabbar's view so that it doesn't have flexible width or flexible right margin.
You have created the frame for UITabBarController *controller
as-
controller.view.frame = CGRectMake(500,500, 500, 500);
the x and y origin is 500
, it looks like that the tab bar controller is added but it's origin is outside the visible frame of the screen.
if let controller = self.storyboard?.instantiateViewController(withIdentifier: "TabController") as? TabController {
addChildViewController(controller)
controller.view.frame = contentView.bounds
contentView.addSubview(controller.view)
controller.didMove(toParentViewController: self)
}
Here 'contentView' is the UIView positioned in ViewController
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.