0

I'm trying to add a subview to a scrollview I have in my view controller:

let size:CGSize = self.view.bounds.size;
self.scrollview.contentSize.width = size.width

pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, self.tableView.frame.origin.y + 130, size.width, size.height), pageMenuOptions: parameters)

self.scrollview.addSubview(pageMenu!.view)

It works to the extent that it adds it in the correct position and height I want it. But for some reason, right now it only expands to about 60% the width of the screen (I need it to be full screen).

Things I've tried

1) Setting it so self.view.frame.width

2) Setting it to the width of another full screen element.

3) Setting it to UIScreen.mainScreen().bounds

I checked the constraints of the scrollview in storyboard and it's configured to be full screen...so I'm not sure why this wont work.

Raymond Rangel
  • 149
  • 3
  • 12

2 Answers2

0

This issue is related to the constraints that need to be set to the scroll view. I have answered a similar question here. Basically you need to specify a constraint for the scroll view's content view's width. See my answer in above link for a detailed description. The problem is that the scrollview adjusts its size to its content view's size even after we provide proper constraints to the scroll view. So we need to specify the constraints of the content view of the scroll view with respect to the scrollview and its superview so that the content in the scrollview fits our requirement.

Community
  • 1
  • 1
Harikrishnan
  • 7,765
  • 13
  • 62
  • 113
0

One thing I noticed was that in your CGRectMake code you are specifying your y origin to be tableViews y value + 130. That seems like the problem to me.

mn1
  • 519
  • 1
  • 5
  • 15