Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I use UIScrollView in Interface Builder?

While I've used UIScrollView successfully in the past by manipulating it programmatically, I'm having trouble getting it to work by setting it up exclusively in Interface Builder.

I have a simple "about" page in my iPhone app. It has a UITextView, some icons, and links to my other apps. I have added all of these views to my UIScrollView, arranging them so that their total size is > 480. When I launch my app, the scrollview displays only the contents that fit on the screen, and nothing scrolls.

Is it possible to do this entirely via IB, or must I manipulate the contentSize via code?

like image 998
George Armhold Avatar asked Jul 16 '09 02:07

George Armhold


People also ask

How do I use scroll view in interface builder?

You can scroll the scrollview in the Storyboard / Interface builder! Select the view inside scrollview in Document Outline, then scroll using your mouse or trackpad, you can see the view move. You should see the view controller elongated to 1100 pt height now.


2 Answers

You forgot to set the contentSize property of the UIScrollView. Strangely enough you can not do this from Interface Builder. You will have to do it from the view controller managing this scroll view.

like image 133
Stefan Arentz Avatar answered Oct 01 '22 04:10

Stefan Arentz


Boby_Wan's answer got me thinking, and I found the following solution to configure the UIScrollView's contentSize from Interface Builder:

  1. Select the UIScrollView in the Storyboard scene
  2. Go to the Identity inspector, create a new User Defined Runtime Attribute (click the + button)
  3. Change the attribute Key Path to contentSize
  4. Change the attribute Type to Size
  5. Now set the Value to {desired content width, desired content height}

eg setting the value to {320, 920} will let the user scroll down a whole extra screen on the iPhone.

(I am using xcode 4.3.3, the project's iOS Deployment Target is 5.1)

When I first did this I received the following error:

Illegal Configuration:
     Size type user defined runtime attributes with Xcode versions prior to 4.3
     MainStoryboard.storyboard

If you too get this error it is simple to fix: select the Storyboard in the Project Navigator, and bring up the File inspector. Find/expand the Interface Builder Document section, and there is a drop down for Development. Ensure this is set to Xcode 4.3

like image 31
Herr Grumps Avatar answered Oct 01 '22 03:10

Herr Grumps