swift [添加子视图和填充]添加子视图并填写#tags:uiview
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift [添加子视图和填充]添加子视图并填写#tags:uiview相关的知识,希望对你有一定的参考价值。
func addChildViewController(viewController: UIViewController, containerView: UIView) {
viewController.willMove(toParentViewController: self)
self.addChildViewController(viewController)
containerView.addSubviewAndFill(subview: viewController.view)
viewController.didMove(toParentViewController: self)
}
func addSubviewAndFill(subview: UIView, edgeInsets: UIEdgeInsets = UIEdgeInsets.zero) {
self.addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-(\(edgeInsets.left))-[view]-(\(edgeInsets.right))-|", metrics: nil, views: ["view": subview]))
self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-(\(edgeInsets.top))-[view]-(\(edgeInsets.bottom))-|", metrics: nil, views: ["view": subview]))
}
以上是关于swift [添加子视图和填充]添加子视图并填写#tags:uiview的主要内容,如果未能解决你的问题,请参考以下文章