如何将 UIControl 添加到 UIScrollView contentView?

发布于 2024-09-14 02:04:58 字数 540 浏览 8 评论 0原文

我想将 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

我还想根据我添加的 UIControl 数量设置 contentView 的框架。我想我会将框架设置在远离屏幕的 Y 方向上,并且每当用户滚动时 UIScrollView 都会将屏幕外的部分滚动到可见状态。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

胡大本事 2024-09-21 02:04:58

UIScrollView 与桌面版本 NSScrollView 有几个方面不同。

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

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

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.

夜夜流光相皎洁 2024-09-21 02:04:58

要将内容添加到 uiscrollview,您需要使用 addSubview 方法向其添加子视图。您设置滚动视图内容的宽度,它将随着用户拖动而移动子视图。

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.

樱花坊 2024-09-21 02:04:58

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文