我做了一个UIScrollView,它包含四个UILabel。我希望所选的UILabel不在屏幕左侧,而是在中央。我附上了两张图片来说明我的意思。在第一张图片上,绿色标签将成为选定的一张,在下一张图片上,蓝色标签将成为选定的一张。在中心选择的UIScrollView分页
有没有办法做到这一点?
这是我的代码:
[scrollView setContentSize:CGSizeMake(428, 65)];
[scrollView setDelegate:self];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 107, 65)];
[label1 setBackgroundColor:[UIColor redColor]];
[label1 setTextAlignment:UITextAlignmentCenter];
[label1 setText:@"Wednesday"];
[scrollView addSubview:label1];
[label1 release];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(107, 0, 107, 65)];
[label2 setBackgroundColor:[UIColor greenColor]];
[label2 setTextAlignment:UITextAlignmentCenter];
[label2 setText:@"Thursday"];
[scrollView addSubview:label2];
[label2 release];
UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(214, 0, 107, 65)];
[label3 setBackgroundColor:[UIColor blueColor]];
[label3 setTextAlignment:UITextAlignmentCenter];
[label3 setText:@"Friday"];
[scrollView addSubview:label3];
[label3 release];
UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(321, 0, 107, 65)];
[label4 setBackgroundColor:[UIColor orangeColor]];
[label4 setTextAlignment:UITextAlignmentCenter];
[label4 setText:@"Saturday"];
[scrollView addSubview:label4];
[label4 release];
你是什么意思的“选定”?滚动查看不会做选择,它只是滚动。 – Adam 2011-04-20 10:38:51
这是正确的,但我已经在scrollview中启用分页,这使得有可能给幻影选择一部分滚动视图。但是如果有其他方法可以做到这一点,我很乐意听到它。我有四个UILabels,其中三个需要一次在屏幕上可见。中间的那个是选中的那个。 – simonbs 2011-04-20 10:42:42
UIScrollView的分页问题是它的contentSize定义了它的页面大小,这意味着你不能有一个完整宽度的contentSize并且以分页的方便滚动1/3的宽度... – tsakoyan 2011-04-20 11:09:54