0
votes

I am using Autolayout with UIScrollView in XCode 9. I wish to have a horizontal paging scrollview with 2-3 pages. I have set a ContentView as the single childview and put constraints on all edges so it aligns with the scroll view. The PageViews are then children of the ContentView.

  UIView
    UIScrollView
       ContentView
          PageView1
          ....

This works great and autolayout works for the scrollview. However I wish to change the content view size, sometimes 2 pages otherwise 3. I have an initial constraint on the ContentView width of twice the outer UIView width with priority set to 250.

If at runtime I change the ContentView frame so the width is increased, this does not get set and the ContentView remains at its original size, I imagine iOS is changing the frame back.

Anyone know how to do this?

1
There are many, many examples of this, if you do a little searching. Here is just one: stackoverflow.com/questions/44931898/…DonMag

1 Answers

1
votes

First i would recommend using UICollectionView / UIStackView for this issue , second changing frame width won't help , every item appended should have leading constraint to the previous trailing , top&bottom&trailing to contentView , then scrollview will autoresize to show that added item