在滚动视图中添加多个视图
我有一个 ScrollView,它将充满很多视图。
我的视图有背景,并将收到动态数量的按钮。
我需要在我的 ScrollView 上添加这些视图。
每个视图都将放置在前一个视图的下方。我的视图有 1024 x 197
我要这样做吗?
预先感谢您的任何帮助。
更多详细信息
我已经在 Interface Builder 上创建了视图(我需要重复的视图),
@interface PortalBookViewController : UIViewController {
UIView *prateleira;
UIScrollView *ScrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *ScrollView;
@property (nonatomic, retain) IBOutlet UIView *prateleira;
@end
我已将该视图(Interface Builder)与 *prateleira 链接起来
- (void)viewDidLoad {
[super viewDidLoad];
for (int i = 0; i < 4; i++) {
switch (i) {
case 0:
prateleira = [prateleira initWithFrame:CGRectMake(0, 0, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
case 1:
prateleira = [prateleira initWithFrame:CGRectMake(0, 198, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
case 2:
prateleira = [prateleira initWithFrame:CGRectMake(0, 384, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
break;
case 3:
prateleira = [prateleira initWithFrame:CGRectMake(0, 582, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
break;
default:
break;
}
}
[ScrollView release];
}
模式详细信息
如果我这样做: [self.ScrollView addSubview:prateleira];
它将向我显示:
我认为问题在于设置视图位置。
I have a ScrollView and it will be filled with lots of views.
My views have a background and will receive a dynamic amount of buttons.
I need to add these views on my ScrollView.
Each view will be placed below the previous. My views have 1024 x 197
Hoe do I do that?
Thanks in advance for any help.
MORE DETAILS
I have created the view (the one I need repeated) on Interface Builder
@interface PortalBookViewController : UIViewController {
UIView *prateleira;
UIScrollView *ScrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *ScrollView;
@property (nonatomic, retain) IBOutlet UIView *prateleira;
@end
I have linked that View(Interface Builder) with *prateleira
- (void)viewDidLoad {
[super viewDidLoad];
for (int i = 0; i < 4; i++) {
switch (i) {
case 0:
prateleira = [prateleira initWithFrame:CGRectMake(0, 0, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
case 1:
prateleira = [prateleira initWithFrame:CGRectMake(0, 198, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
case 2:
prateleira = [prateleira initWithFrame:CGRectMake(0, 384, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
break;
case 3:
prateleira = [prateleira initWithFrame:CGRectMake(0, 582, 1024, 197)];
[ScrollView addSubview:prateleira];
[prateleira release];
break;
break;
default:
break;
}
}
[ScrollView release];
}
MODE DETAILS
If I do that: [self.ScrollView addSubview:prateleira];
it will show me this:
I think the problem is on setting the view position.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需像往常一样添加它们,如下所示:
[self.myScroller addSubview:mytextview];
设置文本视图框架后。或者你还有别的意思吗?
你必须计算循环中的帧,因此每个视图都会添加到下一个视图的下方,如果这就是你的意思......
最好,
马库斯
you simple add those as usual like so:
[self.myScroller addSubview:mytextview];
after you've set the textviews frame. or do you mean something else?
you'd have to calculate the frame in your loop, so each view is added below the next one, if it's that what you mean...
best,
marcus
使用addSubview:
Use addSubview:
解决方案是创建一个 uiview 对象,如下所示:
它工作得很好。
the solution was to create a uiview object like:
It works perfectly.