在滚动视图中添加多个视图

发布于 2024-11-30 06:06:47 字数 1929 浏览 0 评论 0原文

我有一个 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:

enter image description here

I think the problem is on setting the view position.

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

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

发布评论

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

评论(3

离线来电— 2024-12-07 06:06:47

您只需像往常一样添加它们,如下所示:

[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

走野 2024-12-07 06:06:47

使用addSubview:

[self.scrollView addSubview:myNewView];

Use addSubview:

[self.scrollView addSubview:myNewView];
瞎闹 2024-12-07 06:06:47

解决方案是创建一个 uiview 对象,如下所示:

UIView * shelf_view (NSInteger x, NSInteger y) {

    UIView *shelf = [[UIView alloc] initWithFrame:CGRectMake(x, y, 1024, 197)];
    UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shelf.png"]];
    [shelf addSubview:background];
    return shelf;

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    for (int i = 0; i < 4; i++) {
        switch (i) {
            case 0:
                [ScrollView addSubview: shelf_view(0, 0)];
                break;
            case 1:
                [ScrollView addSubview: shelf_view(0, 197)];
                break;
            case 2:
                [ScrollView addSubview: shelf_view(0, 512)];
                break;
            case 3:
                [ScrollView addSubview: shelf_view(0, 777)];
                break;
            default:
                break;
        }
    }
    [super viewDidLoad];
    [ScrollView release];


}

它工作得很好。

the solution was to create a uiview object like:

UIView * shelf_view (NSInteger x, NSInteger y) {

    UIView *shelf = [[UIView alloc] initWithFrame:CGRectMake(x, y, 1024, 197)];
    UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shelf.png"]];
    [shelf addSubview:background];
    return shelf;

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    for (int i = 0; i < 4; i++) {
        switch (i) {
            case 0:
                [ScrollView addSubview: shelf_view(0, 0)];
                break;
            case 1:
                [ScrollView addSubview: shelf_view(0, 197)];
                break;
            case 2:
                [ScrollView addSubview: shelf_view(0, 512)];
                break;
            case 3:
                [ScrollView addSubview: shelf_view(0, 777)];
                break;
            default:
                break;
        }
    }
    [super viewDidLoad];
    [ScrollView release];


}

It works perfectly.

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