Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Resize container view iOS 8 swift based on the device

lc87lc87 Posts: 1New Users Noob
I am a newbie to the iOS development and I am trying to create a table view with multiple sections with a container view controller, embedding a table view, as you can see in the picture attached in this post.

I am having problem resizing the container view to fit properly the available space; I would like, that based on the device I'm running the app on, the container view could calculate it's height dynamically. In the picture I have attached there are two red sticks to show the desired height of the container view at runtime.

The solution I tried to implement is the following one:
override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    contView.frame.size.height = self.view.bounds.size.height -CGFloat(contView.frame.origin.y)
}

The height of the container view is the difference between the bounds.size.height of the view and the frame.origin.y of the container view. That pretty much solved my problem but I would like your assistance to figure out if there is a clever and smarter way to solve the problem. Thanks in advance for your kindness and patience.
Sign In or Register to comment.