praks5432
praks5432

Reputation: 7792

UIScrollView in Interface Builder not working

I originally had a normal view with a bunch of stuff in it, and I want that view to be an UIScrollView, so I created a new ScrollView and dragged everything over. The view is not scrolling.

After looking around - I unchecked use autolayout, but that didn't work. I also realize that this could be solved by setting contentSize, but I have access to this view through a variable that is of type UIView, and not UIScrollView. In other words I would be doing -

self.someController.view.contentSize = //something

where self.someController.view is only an UIView and contentSize is not a property of UIView(or at least that's what I'm seeing- I get compiler warnings).

Why is this scroll view not scrolling?

EDIT -

So I stupidly forgot I can cast - I did that, but it's still not working -

        UIScrollView* basicCardView = ((UIScrollView *)self.detailController.view);
    basicCardView.contentSize = CGSizeMake(basicCardView.frame.size.width * 12,
                                           basicCardView.frame.size.height);

Upvotes: 0

Views: 826

Answers (2)

danh
danh

Reputation: 62676

Elto has it correct. To elaborate: In your view controller .m say it's called MyViewController:

@interface MyViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end

Go back to storyboard, select your view controller and select the connections tab (last one on the upper right). You should now see an outlet called scrollView. Drag a connection from that outlet to the scroll view that you added to the scene.

Now the content size code can be written. Just to get it working, use large constants in content size, like:

self.scrollView.contentSize = CGSizeMake(1000, 1000);

The size you're setting in the post (on the wrong view) looks like it's just the size of one of the subviews. You want the content size of the scroll view to be more like a multiple of the scrollView's size. You want the rectangle it can scroll within to at least encompass the frame (not the bounds) of every subview it contains.

Upvotes: 0

Elto
Elto

Reputation: 429

You need to connect your scrollview to Iboutlet var in .m . Create var in your interface:

IBOutlet UIScrollView *scrollview; 

And connect to your scrollview in storyboard, then you can set contentsize.

[scrollview setContentSize:CGSizeMake(2000,200)];

Upvotes: 2

Related Questions