Search code examples
iosswiftstoryboardframeviewcontroller

Swift SubView Positioning to StoryBoard Item


I have a View Controller with a NavBar Item added through the storyboard interface. However, I made a Collection View programmatically and would like it to be positioned on the y-axis so it always right underneath the NavBar for any screen size. I don't know how to go about this but the code below is how its placed in the view Controller right now.

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        collectionView?.frame = CGRect(x: 0, y: 64, width: view.frame.size.width, height: 65).integral
    }

Solution

  • collectionView?.frame = CGRect(x: 0, y: NavBar.frame.maxY , width: view.frame.size.width, height: 65).integral