Designing inside a scrollview in xcode 4.2 with storyboards

前端 未结 9 815
梦如初夏
梦如初夏 2020-11-29 02:46

I have a vertically scrolling uiscrollview - imagine an \'about this app\' page of a tab bar app which goes on a bit and requires a scrollview. It only contains a few images

9条回答
  •  一生所求
    2020-11-29 03:34

    New: 3/26/2013

    I stumbled upon what I think is even simpler way of dealing with UIScrollView directly in storyboard.

    1. No code needed, just storyboard settings. This maybe new in iOS6.1 / Xcode 4.6
    2. No need to disable constraints (i.e. uncheck "Use autolayout" in File Inspector for storyboard file)
    3. No need to add UIScrollView* scrollView; in .h
    4. No need to add self.scrollView.contentSize = ... in overrides of viewWillAppear or viewDidLoad

    Here is what I did (important parts highlighted with **): (see code)

    1. Create a new project with storyboard enabled
    2. Drop in a UIScrollView, set class in identity inspector for view controller
    3. In attributes Inspector, change Size under simulated metrics to Freeform**
    4. Select scroll View; In attributes inspector, turn on "scroll enabled" and "background" to "White" (you'll figure out why - if you don't)
    5. Under Size Inspector (with scroll view selected) change the height to 900 for example**
    6. Add buttons, one on top and one at the bottom
    7. Add a default handler for buttonTouchUpInside for both buttons and simply Log sender.

    See Code Select the View Controller and scroll view and check inspectors.

提交回复
热议问题