-1

I want to fix PageViewController views in specific view. When i load into ViewController main view it's working fine, but when i load it in subView PageViewController not fixing in that subView. How to fix PageViewController in subview.

Image 1, red colour view is ,my subView I want to fix PageViewController in this red colour view.

enter image description here

image 2 , this is I'm getting.

enter image description here

Naresh
  • 16,698
  • 6
  • 112
  • 113
  • What do you mean by fix it? Does it refer to constraints? – PGDev Jul 01 '19 at 07:17
  • @ PGDev, I want to fix size of PageViewController in subView. This is my code https://stackoverflow.com/questions/56801714/in-pageviewcontroller-navigation-not-working – Naresh Jul 01 '19 at 09:51
  • @iOS - in the code in your other question, you are calling `pageControllerView.addSubview(pageContainer.view)` ... but you are not setting the frame and/or constraints on `pageContainer.view`. You need to do so, in order to match its "page views" to the size of your (red) subview. – DonMag Jul 01 '19 at 12:28
  • @ DonMag, how to fix constraints in **pageContainer.view** can you please give small example for me... – Naresh Jul 01 '19 at 12:30

1 Answers1

1

Based on your code in your other question, you are adding your page view to your (red) subview but not setting its frame.

    // Create the page container
    pageContainer = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
    pageContainer.delegate = self
    pageContainer.dataSource = self
    pageContainer.setViewControllers([page1], direction: UIPageViewController.NavigationDirection.forward, animated: false, completion: nil)

    // Add it to the view
    pageControllerView.addSubview(pageContainer.view)

    // set the frame of the pageContainer view to match its superview (the red view)
    pageContainer.view.frame = pageControllerView.bounds
    // let it resize if needed (such as device rotation)
    pageContainer.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

This should solve the issue.

DonMag
  • 69,424
  • 5
  • 50
  • 86
  • @ DonMag, one more new question, can you please answer it. How to set navigation bar back button text. I'm unable to change back btn text . my code is – Naresh Jul 01 '19 at 13:02
  • let backItem = UIBarButtonItem() backItem.title = "Call Log" self.navigationItem.backBarButtonItem = backItem if UIDevice.current.userInterfaceIdiom == .pad { backItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Exo2-Medium", size: 20)!], for: UIControl.State.normal); } else { backItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Exo2-Medium", size: 15)!], for: UIControl.State.normal); } – Naresh Jul 01 '19 at 13:02