views:

114

answers:

3

I want to add UIControls to a UIScrollView, eg.

UIControl *couponView = [[UIControl alloc] initWithFrame:CGRectMake(drawX,drawY,couponWidth,couponHeight)];
couponView.backgroundColor = [UIColor redColor];    

[[scrollView contentView] addSubview:couponView]; //may not respond
    [scrollview.contentView addSubview:couponView]; //not a member

I also want to set the frame of the contentView based on how many UIControls I'm adding. I'm thinking I'll set the frame far in the Y direction off screen, and the UIScrollView will scroll the off-screen parts into visibility whenever the user scrolls.

I didn't see a contentView property in UIScrollView.. how can I access the contentView?

A: 

To add content to a uiscrollview, you need to add subviews to it, with the addSubview method. You set the width of the scrollView content and it will move the subviews as the user drags.

Tom H
A: 

You'd have to add that property yourself. Just add a regular UIView to the scrollview with addSubview.

Matt Williamson
+1  A: 

UIScrollView differs from the desktop version NSScrollView in a couple of ways.

One of them is that it does not provide contentView or documentView accessors. Instead, you'd add content directly to the UIScrollView.

Just add subviews to the scroll view and set its bounds (or contentSize) to contain all the subviews.

Nikolai Ruhe