BaseCollectionViewController.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // BaseCollectionViewController.m
  3. // CommonLibrary
  4. //
  5. // Created by Alexi on 3/12/14.
  6. // Copyright (c) 2014 CommonLibrary. All rights reserved.
  7. //
  8. #import "BaseCollectionViewController.h"
  9. #import "UIViewController+Layout.h"
  10. #import "IOSDeviceConfig.h"
  11. #define kCollectionViewIdentifier @"CollectionViewCellIdentifier";
  12. @interface BaseCollectionViewController ()
  13. @end
  14. @implementation BaseCollectionViewController
  15. - (UICollectionViewLayout *)collectionLayout
  16. {
  17. if ([IOSDeviceConfig sharedConfig].isIPad)
  18. {
  19. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  20. layout.itemSize = CGSizeMake(220, 280);
  21. layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
  22. layout.minimumInteritemSpacing = 20;
  23. layout.minimumLineSpacing = 20;
  24. return layout;
  25. }
  26. else
  27. {
  28. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  29. layout.itemSize = CGSizeMake(130, 180);
  30. layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
  31. layout.minimumInteritemSpacing = 10;
  32. layout.minimumLineSpacing = 20;
  33. return layout;
  34. }
  35. }
  36. - (id)init
  37. {
  38. UICollectionViewLayout *layout = [self collectionLayout];
  39. return [self initWithCollectionViewLayout:layout];
  40. }
  41. - (void)viewDidLoad
  42. {
  43. [super viewDidLoad];
  44. self.view.backgroundColor = kClearColor;
  45. [self configCollectionView];
  46. }
  47. - (NSString *)cellIdentifier
  48. {
  49. return kCollectionViewIdentifier;
  50. }
  51. - (void)configCollectionView
  52. {
  53. self.collectionView.backgroundColor = [UIColor clearColor];
  54. [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:[self cellIdentifier]];
  55. }
  56. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  57. {
  58. return 100;
  59. }
  60. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  61. {
  62. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[self cellIdentifier] forIndexPath:indexPath];
  63. cell.backgroundColor = [UIColor randomFlatColor];
  64. return cell;
  65. }
  66. #pragma mark -
  67. #pragma Same as CommonBaseViewController method
  68. - (void)viewWillAppear:(BOOL)animated
  69. {
  70. [super viewWillAppear:animated];
  71. if ([IOSDeviceConfig sharedConfig].isIPad)
  72. {
  73. [self layoutOnViewWillAppear];
  74. }
  75. }
  76. - (void)layoutSubviewsFrame
  77. {
  78. self.collectionView.frame = self.view.bounds;
  79. [super layoutSubviewsFrame];
  80. }
  81. @end