HXPhotoEditChartletContentViewCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // HXPhotoEditChartletContentViewCell.m
  3. // photoEditDemo
  4. //
  5. // Created by Silence on 2020/7/2.
  6. // Copyright © 2020 Silence. All rights reserved.
  7. //
  8. #import "HXPhotoEditChartletContentViewCell.h"
  9. #import "HXPhotoEditChartletModel.h"
  10. #import "HXPhotoEditChartletListView.h"
  11. #import "HXPhotoDefine.h"
  12. @interface HXPhotoEditChartletContentViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>
  13. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  14. @property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;
  15. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionLeftConstraint;
  16. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionRightConstraint;
  17. @end
  18. @implementation HXPhotoEditChartletContentViewCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. if (@available(iOS 11.0, *)){
  23. [self.collectionView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
  24. }
  25. CGFloat width;
  26. UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  27. if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown || HX_UI_IS_IPAD) {
  28. width = (HX_ScreenWidth - 5 * 20) / 4;
  29. self.flowLayout.sectionInset = UIEdgeInsetsMake(75, 20, 20, 20);
  30. }else {
  31. self.flowLayout.sectionInset = UIEdgeInsetsMake(75, 20 + hxTopMargin, 20, 20 + hxTopMargin);
  32. width = ((HX_ScreenWidth - hxTopMargin * 2) - 9 * 20) / 8;
  33. }
  34. self.flowLayout.itemSize = CGSizeMake(width, width);
  35. self.flowLayout.minimumLineSpacing = 20;
  36. self.flowLayout.minimumInteritemSpacing = 20;
  37. [self.collectionView registerClass:[HXPhotoEditChartletListViewCell class] forCellWithReuseIdentifier:@"HXPhotoEditChartletListViewCell_Id"];
  38. }
  39. - (void)setModels:(NSArray<HXPhotoEditChartletModel *> *)models {
  40. _models = models;
  41. [self.collectionView reloadData];
  42. }
  43. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  44. return self.models.count;
  45. }
  46. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  47. HXPhotoEditChartletListViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HXPhotoEditChartletListViewCell_Id" forIndexPath:indexPath];
  48. cell.model = self.models[indexPath.item];
  49. return cell;
  50. }
  51. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  52. if (self.selectCellBlock) {
  53. HXPhotoEditChartletListViewCell *cell = (HXPhotoEditChartletListViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
  54. if (!cell.imageView.image) {
  55. return;
  56. }
  57. self.selectCellBlock(cell.imageView.image);
  58. }
  59. }
  60. @end