在 uiscrollview 中制作 uisegmentedcontrol

发布于 2024-09-27 15:31:52 字数 591 浏览 1 评论 0原文

我想使用一个非常大的分段控制组件,所以我有想法将其制作在 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];

但是滚动视图没有让分段控件被看到。 我的错误在哪里?

I want to use a very large segmentedcontrol component so I had the idea to make it in a uiscrollview ..so by scrolling horizontally user can choose the appropriate item.
I wrote this code:

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

but the scroll view didn't let the segmentedcontrol to be seen.
where was my mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场春暖 2024-10-04 15:31:52

也许这会对您有所帮助:

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

Maybe this will help you:

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];
永言不败 2024-10-04 15:31:52

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

You can use UICollectionView to scroll horizontally and use buttons as cells.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文