【问题标题】:Creating a UIContainerView() programmatically and changing its height以编程方式创建 UIContainerView() 并更改其高度
【发布时间】:2017-05-16 11:37:32
【问题描述】:

我正在以编程方式创建一个容器视图。但是,我无法改变它的高度。我以编程方式设置它,但没有任何效果。

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。但没有任何运气。 有什么帮助吗?谢谢

【问题讨论】:

  • 你在故事板中添加了约束吗?您真的需要以编程方式创建容器视图吗?
  • 附带说明,没有UIContainerView() 这样的东西。
  • 是的,但没有运气:/

标签: ios swift uiview uicontainerview


【解决方案1】:

您尚未在containerView 上设置clipsToBounds,该属性的默认值为false

在您正在设置containerView 的框架下方添加此行:

containerView.clipsToBounds = true

另外,作为一些阅读材料,我想向您介绍this discussion clipsToBounds 属性。

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 2015-06-24
    • 2015-08-10
    • 2023-01-17
    • 2014-11-21
    • 2014-01-22
    • 2017-04-25
    • 2014-07-05
    • 1970-01-01
    相关资源
    最近更新 更多