2017-01-02 91 views
0

我以编程方式创建容器视图。但是,我无法改变它的身高。我以编程方式设置它,但没有任何影响。以编程方式创建UIContainerView()并更改其高度

let supportView: UIView = UIView() 
let containerView = UIView() 

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(true) 
    self.containerView.frame = CGRect(x: self.view.frame.size.width - 100, y: 200, width: 225, height: 70) 
    print(self.containerView.frame.height) 
    self.containerView.backgroundColor = UIColor.gray 
    self.containerView.layer.cornerRadius = 20 

    self.view.addSubview(self.containerView) 

    let controller = storyboard!.instantiateViewController(withIdentifier: "Storyboard2") 
    addChildViewController(controller) 

    containerView.addSubview(controller.view) 
    controller.didMove(toParentViewController: self) 
} 

我创建故事板具有标识符“Storyboard2”视图控制器。而且我已经把它的高度设置在70了。但没有任何运气。 任何帮助?由于

+0

你有没有在故事板中添加约束?你真的需要以编程方式创建容器视图吗? –

+0

可能重复的[我可以创建一个UIContainerView程序?](http://stackoverflow.com/questions/29694628/can-i-create-a-uicontainerview-programatically) – dirtydanee

+0

作为一个方面说明,没有这样的事情'UIContainerView()'。 – dirtydanee

回答

1

您没有设置containerViewclipsToBounds,并且该属性的默认值是false

添加此行只是根据你的设置containerView的框架:

containerView.clipsToBounds = true

此外,一些阅读材料,我想向大家介绍this discussion有关clipsToBounds财产。

+0

感谢您的回答,它的工作! –

相关问题