0

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

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Marc Ibrahim
  • 299
  • 5
  • 18

1 Answers1

1

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.

Community
  • 1
  • 1
dirtydanee
  • 6,081
  • 2
  • 27
  • 43