cen*_*ree 7 cocoa-touch objective-c ios
我正在尝试创建一个非常长的分段控制器,让用户在众多选项中进行选择.如何在Scroll View中获取它?
我试过拖放它但它不允许我滚动它.
尝试通过以下代码在滚动视图中添加分段控件:
- (void)viewDidLoad
{
[super viewDidLoad];
journals = [[NSMutableArray alloc]init];
self.tableView.dataSource = self;
self.tableView.delegate = self;
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 49, 320, 29)];
self.segmentedControl.frame = CGRectMake(0, 0, 640, 29);
scrollView.contentSize = CGSizeMake(self.segmentedControl.frame.size.width, self.segmentedControl.frame.size.height -1);
scrollView.showsHorizontalScrollIndicator = NO;
self.segmentedControl.selectedSegmentIndex = 0;
[scrollView addSubview:self.segmentedControl];
[self.view addSubview:scrollView];
[self fillJournals];
// Do any additional setup after loading the view, typically from a nib.
}
Run Code Online (Sandbox Code Playgroud)
这是一篇关于如何在滚动视图中创建分段控件的帖子
http://penningthoughtsandmemoirs.com/2013/12/16/sliding-segmented-control/
从以下位置下载源代码:
https://github.com/sahilriaz1110/SlidingSegmentedControl
您必须设置 的内容大小UIScrollView,否则它不会滚动。
myScrollView.contentSize = mySegmentedControl.frame.size;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8744 次 |
| 最近记录: |