views:

193

answers:

1

Gentle programmers, here for your inspection I present code that creates a scrolling view and populates it with buttons:

UIScrollView * testScroll = 
  [[UIScrollView alloc]initWithFrame:CGRectMake(10, 20, 80, 90)];
CGFloat y = 0;
for (int i = 0;i<5;i++) {
   UIButton *mybut = [[UIButton alloc] initWithFrame:CGRectMake(0, y, 75, 25)];

   NSString *title = [NSString stringWithFormat:@"button: %d",i]
   [mybut setTitle:title forState:UIControlStateNormal];
   [mybut addTarget:self action:@selector(Ok:)
      forControlEvents:UIControlEventTouchUpInside];
   y = y+35;
}   

This is all well and good, for those that like scrolling lists of buttons. However, I wish to have a scrolling list of labels! How might I adjust this code to achieve this, my ultimate goal?

+1  A: 

Well, if I could understand it right, you want something like that:

UIScrollView * testScroll = 
  [[UIScrollView alloc]initWithFrame:CGRectMake(10, 20, 80, 90)];
CGFloat y = 0;
for (int i = 0;i<5;i++) {
   UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, y, 75, 25)];

   NSString *text = [NSString stringWithFormat:@"Label: %d",i]
   [myLabel setText:title];
   [testScroll addSubview:myLabel];
   [myLabel release];
   y = y+35;
}

Let me know if it is what you want.

Cheers,
VFN

PS: Don't you prefer to use a table to do this, in the case you have many labels?

vfn