我怎样才能在UIScrollView中添加标签?

时间:2010-01-07 12:24:02

标签: iphone uiscrollview

温和的程序员,在这里供您检查我提供了创建滚动视图的代码,使用按钮填充它

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;
}   

对于喜欢滚动按钮列表的人来说,这一切都很好。但是,我希望有一个标签的滚动列表!我如何调整此代码来实现这一目标,我的最终目标

1 个答案:

答案 0 :(得分:1)

好吧,如果我能理解它,你需要这样的东西:

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;
}

让我知道这是不是你想要的。

干杯,
VFN

PS:如果你有很多标签,你不喜欢用表来做这件事吗?