0

私はScrollViewを持っていて、それはたくさんのビューでいっぱいになります。

私のビューには背景があり、動的な量のボタンを受け取ります。

ScrollViewにこれらのビューを追加する必要があります。

各ビューは前のビューの下に配置されます。私のビューは1024x197です

鍬私はそれをしますか?

助けてくれてありがとう。

詳細

Interface Builderでビュー(繰り返す必要があるビュー)を作成しました

@interface PortalBookViewController : UIViewController {
    UIView *prateleira;
    UIScrollView *ScrollView;
}

@property (nonatomic, retain) IBOutlet UIScrollView *ScrollView;
@property (nonatomic, retain) IBOutlet UIView *prateleira;

@end

そのView(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];それは私にこれを示すでしょう:

ここに画像の説明を入力してください

問題はビュー位置の設定にあると思います。

4

3 に答える 3

1

あなたは単純に次のようにそれらをいつものように追加します:

[self.myScroller addSubview:mytextview];

textviewsフレームを設定した後。またはあなたは何か他のものを意味しますか?

ループ内のフレームを計算する必要があるため、各ビューが次のビューの下に追加されます。

最高、マーカス

于 2011-08-17T18:55:26.240 に答える
0

addSubviewを使用します。

[self.scrollView addSubview:myNewView];
于 2011-08-17T18:53:15.990 に答える
0

解決策は、次のような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];


}

それは完璧に動作します。

于 2011-08-17T20:32:32.630 に答える