Frage

I want to create a scrollView having many sub views as shown in image.

Image of expected scrollview

All views having a labels & image within it. Number of views add in scrollView are dynamic. And data of that views is also dynamic.

So that I can't make a static view in program and use it for display.

I want to make scrollview's subview like TableView with custom cells. Like make a object of that TableViewCell and use it.

Can I use ViewController for that?

War es hilfreich?

Lösung

If i understood you question true, you need something like dynamic content of scrollView. So you need an array to control how many cell you will put into scrollView and create label, imageView or whatever you need. For example like that;

//You will need to clean your scrollView Content in everytime

 for(UIView *view in [yourScrollView subviews]){

    [view removeFromSuperview];
}

for(int i=0;i!=[yourArray count];i++)
{
    labels[i]=[[UILabel alloc]init];
    //anyInteger is about your views place.
    views[i]=[[UIView alloc]initWithFrame:CGRectMake(21, i*anyInteger, 300, 50)];
    views[i].backgroundColor=[UIColor colorWithRed:0.1 green:0.2 blue:1.8 alpha:0.0];
    [views[i] addSubview:labels[i]];
    [yourScrollView addSubview:views[i]];
}

These codes will help you about insert objects in yourScrollView. I didnt test this yet but i guess it will give you an idea.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top