FBScrollViewController.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBScrollViewController.h"
  10. #import "FBTableDataSource.h"
  11. static const CGFloat FBSubviewHeight = 40.0;
  12. @interface FBScrollViewController ()
  13. @property (nonatomic, weak) IBOutlet UIScrollView *scrollView;
  14. @property (nonatomic, strong) IBOutlet FBTableDataSource *dataSource;
  15. @end
  16. @implementation FBScrollViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self setupLabelViews];
  20. self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame), self.dataSource.count * FBSubviewHeight);
  21. }
  22. - (void)setupLabelViews
  23. {
  24. NSUInteger count = self.dataSource.count;
  25. for (NSInteger i = 0 ; i < count ; i++) {
  26. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, i * FBSubviewHeight, CGRectGetWidth(self.view.frame), FBSubviewHeight)];
  27. label.text = [self.dataSource textForElementAtIndex:i];
  28. label.textAlignment = NSTextAlignmentCenter;
  29. [self.scrollView addSubview:label];
  30. }
  31. }
  32. @end