Creating a UIContainerView() programmatically and changing its height

472 views Asked by At

I'm creating a container view programmatically. However, i'm not able to change its height. I'm setting it programmatically but without any effect.

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)
}

I created the view controller with identifier "Storyboard2" in the storyboard. And i've set its height to 70 there too. But without any luck. Any Help? Thanks

1

There are 1 answers

0
dirtydanee On BEST ANSWER

You have not set the clipsToBounds on containerView, and the default value of that property is false.

Add this line just under you are setting the containerView's frame:

containerView.clipsToBounds = true

Also, as some reading material, i would like to present to you this discussion about the clipsToBounds property.