在uiscrollview中制作一个uisegmented控件 [英] make an uisegmentedcontrol in an uiscrollview

查看:50
本文介绍了在uiscrollview中制作一个uisegmented控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一个非常大的segmentedcontrol组件,所以我有一个想法可以在uiscrollview ..中实现,因此通过水平滚动,用户可以选择适当的项目. 我写了这段代码:

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

,但是滚动视图没有显示segmentedcontrol. 我的错误在哪里?

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

推荐答案

也许这会帮助您:

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

这篇关于在uiscrollview中制作一个uisegmented控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆