2

我想使用一个非常大的分段控制组件,所以我想在 uiscrollview 中制作它。所以通过水平滚动用户可以选择适当的项目。我写了这段代码:

CGRect rect = [[UIScreen mainScreen] applicationFrame];
CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, 2*rect.size.width , kPaletteHeight);
seg.frame = frame;

scroll.frame = frame;
scroll.contentSize = CGSizeMake(frame.size.width * 2,frame.size.height);
scroll.showsHorizontalScrollIndicator = YES;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
[scroll addSubview:seg];

但是滚动视图并没有让segmentedcontrol被看到。我的错误在哪里?

4

2 回答 2

6

也许这会帮助你:

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)];
 scroll.contentSize = CGSizeMake(320, 700);
 scroll.showsHorizontalScrollIndicator = YES;

 NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil];
 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
 segmentedControl.frame = CGRectMake(35, 200, 250, 50);
 segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
 segmentedControl.selectedSegmentIndex = 1;

 [scroll addSubview:segmentedControl];
 [segmentedControl release]; 
 [self.view addSubview:scroll];
于 2011-07-14T06:56:58.953 回答
0

您可以使用 UICollectionView 水平滚动并将按钮用作单元格。

于 2017-05-08T06:28:39.907 回答