4

我想将 UIControls 添加到 UIScrollView,例如。

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

我还想根据我添加的 UIControls 设置 contentView 的框架。我在想我会将框架设置在远离屏幕的 Y 方向上,并且 UIScrollView 会在用户滚动时将屏幕外部分滚动到可见性中。

我没有在 UIScrollView 中看到 contentView 属性。如何访问 contentView?

4

3 回答 3

5

UIScrollViewNSScrollView在几个方面与桌面版本不同。

其中之一是它不提供contentViewdocumentView访问器。相反,您可以将内容直接添加到UIScrollView.

只需将子视图添加到滚动视图并设置其边界(或contentSize)以包含所有子视图。

于 2010-08-11T15:02:14.180 回答
0

要将内容添加到 uiscrollview,您需要使用 addSubview 方法向其中添加子视图。您设置 scrollView 内容的宽度,它会在用户拖动时移动子视图。

于 2010-08-11T14:55:20.983 回答
0

您必须自己添加该属性。只需使用 addSubview 将常规 UIView 添加到滚动视图。

于 2010-08-11T14:56:28.407 回答