CPDFArrowStyleView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // CPDFArrowStyleView.m
  3. // compdfkit-tools
  4. //
  5. // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFArrowStyleView.h"
  13. #import "CPDFArrowStyleCell.h"
  14. #import "CPDFDrawArrowView.h"
  15. #import <compdfkit_tools/CPDFColorUtils.h>
  16. @interface CPDFArrowStyleView () <UICollectionViewDelegate,UICollectionViewDataSource>
  17. @property (nonatomic, strong) UIButton *backBtn;
  18. @property (nonatomic, strong) UILabel *titleLabel;
  19. @property (nonatomic, strong) UICollectionView *collectView;
  20. @property (nonatomic, strong) UIView *headerView;
  21. @end
  22. @implementation CPDFArrowStyleView
  23. #pragma mark - Initializers
  24. - (instancetype)initWirhTitle:(NSString *)title {
  25. if (self = [super init]) {
  26. self.headerView = [[UIView alloc] init];
  27. self.headerView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  28. self.headerView.layer.borderWidth = 1.0;
  29. self.headerView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  30. [self addSubview:self.headerView];
  31. self.backBtn = [[UIButton alloc] init];
  32. [self.backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBarImageUndo" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  33. [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
  34. [self.headerView addSubview:self.backBtn];
  35. self.titleLabel = [[UILabel alloc] init];
  36. self.titleLabel.text = title;
  37. [self.headerView addSubview:self.titleLabel];
  38. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  39. layout.itemSize = CGSizeMake((self.frame.size.width - 5.0* 7)/6, 30);
  40. layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
  41. layout.minimumInteritemSpacing = 5;
  42. layout.minimumLineSpacing = 5;
  43. self.collectView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, self.frame.size.width, self.frame.size.height) collectionViewLayout:layout];
  44. [self.collectView registerClass:[CPDFArrowStyleCell class] forCellWithReuseIdentifier:@"cell"];
  45. self.collectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  46. self.collectView.delegate = self;
  47. self.collectView.dataSource = self;
  48. self.collectView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  49. [self addSubview:self.collectView];
  50. self.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  51. }
  52. return self;
  53. }
  54. - (void)layoutSubviews {
  55. [super layoutSubviews];
  56. self.backBtn.frame = CGRectMake(15, 5, 60, 50);
  57. self.titleLabel.frame = CGRectMake((self.frame.size.width - 100)/2, 5, 100, 50);
  58. self.headerView.frame = CGRectMake(0, 0, self.bounds.size.width, 50);
  59. }
  60. #pragma mark - Action
  61. - (void)buttonItemClicked_back:(id)sender {
  62. [self removeFromSuperview];
  63. if (self.delegate && [self.delegate respondsToSelector:@selector(arrowStyleRemoveView:)]) {
  64. [self.delegate arrowStyleRemoveView:self];
  65. }
  66. }
  67. #pragma mark - UICollectionViewDataSource
  68. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  69. return CGSizeMake((self.frame.size.width - 5.0* 7)/6, 30);
  70. }
  71. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  72. return 6;
  73. }
  74. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  75. CPDFArrowStyleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  76. cell.contextView.selectIndex = indexPath.item;
  77. [cell.contentView setNeedsDisplay];
  78. cell.backgroundColor = [UIColor clearColor];
  79. return cell;
  80. }
  81. #pragma mark - UICollectionViewDelegate
  82. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  83. NSArray<UICollectionViewCell *> *cells = [collectionView visibleCells];
  84. for (UICollectionViewCell *cell in cells) {
  85. ((CPDFArrowStyleCell *)cell).contextView.backgroundColor = [UIColor whiteColor];
  86. }
  87. CPDFArrowStyleCell *cell = (CPDFArrowStyleCell *)[collectionView cellForItemAtIndexPath:indexPath];
  88. cell.contextView.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  89. if (self.delegate && [self.delegate respondsToSelector:@selector(arrowStyleView:selectIndex:)]) {
  90. [self.delegate arrowStyleView:self selectIndex:indexPath.item];
  91. }
  92. }
  93. @end