2

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?

GingerHead
  • 8,130
  • 15
  • 59
  • 93

1 Answers1

2

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.

Yucel Bayram
  • 1,653
  • 2
  • 22
  • 41
  • I think it works but is there any another way like display custom cell in UITableView? Means one class is having only view containing label,image, etc. and just need to make an object of that in that class and assign value like objViewClass.lblName = @"yucel" . – Yashpal Javia Feb 12 '14 at 08:12
  • Yes i guess you can make it. Create a class, write initWithnibName method and give contents which you want to this class show. Then call this like that class *objectOfClass=[[class alloc]init]; objectOfClass.view.frame=CGRectMake(0, 100, 800 , 900); [ self.view addSubview:objectOfClass.view]; – Yucel Bayram Feb 12 '14 at 08:40
  • Thanks Again Yucel, I got the answer from this [link](http://stackoverflow.com/questions/18897582/adding-uiviewcontrollers-to-uiscrollview) also. – Yashpal Javia Feb 12 '14 at 11:23