CShapeSelectView.m 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // CShapeSelectView.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 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 "CShapeSelectView.h"
  13. #if __has_include(<ComPDFKit_Tools/ComPDFKit_Tools.h>)
  14. #import <ComPDFKit_Tools/ComPDFKit_Tools.h>
  15. #else
  16. #import "ComPDFKit_Tools.h"
  17. #endif
  18. @interface CShapeSelectView ()
  19. @property (nonatomic, strong) NSMutableArray *buttonArray;
  20. @end
  21. @implementation CShapeSelectView
  22. #pragma mark - Initializers
  23. - (instancetype)initWithFrame:(CGRect)frame {
  24. if (self = [super initWithFrame:frame]) {
  25. self.buttonArray = [NSMutableArray array];
  26. UIButton *squareButton = [[UIButton alloc] init];
  27. [squareButton setImage:[UIImage imageNamed:@"CPDFShapeArrowImageSquare" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  28. [squareButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  29. squareButton.tag = CShapeSelectTypeSquare;
  30. [self addSubview:squareButton];
  31. [self.buttonArray addObject:squareButton];
  32. UIButton *circleButton = [[UIButton alloc] init];
  33. [circleButton setImage:[UIImage imageNamed:@"CPDFShapeArrowImageCircle" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  34. [circleButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  35. circleButton.tag = CShapeSelectTypeCircle;
  36. [self addSubview:circleButton];
  37. [self.buttonArray addObject:circleButton];
  38. UIButton *arrowButton = [[UIButton alloc] init];
  39. [arrowButton setImage:[UIImage imageNamed:@"CPDFShapeArrowImageArrow" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  40. [arrowButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  41. arrowButton.tag = CShapeSelectTypeArrow;
  42. [self addSubview:arrowButton];
  43. [self.buttonArray addObject:arrowButton];
  44. UIButton *lineButton = [[UIButton alloc] init];
  45. [lineButton setImage:[UIImage imageNamed:@"CPDFShapeArrowImageLine" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  46. [lineButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  47. lineButton.tag = CShapeSelectTypeLine;
  48. [self addSubview:lineButton];
  49. [self.buttonArray addObject:lineButton];
  50. }
  51. return self;
  52. }
  53. - (void)layoutSubviews {
  54. [super layoutSubviews];
  55. for (int i = 0; i < self.buttonArray.count; i++) {
  56. ((UIButton *)self.buttonArray[i]).frame = CGRectMake((self.bounds.size.width - (self.bounds.size.height*4))/5*(i+1) + self.bounds.size.height*i, 0, self.bounds.size.height, self.bounds.size.height);
  57. }
  58. }
  59. #pragma mark - Action
  60. - (void)buttonItemClicked_select:(UIButton *)button {
  61. for (int j = 0; j < self.buttonArray.count; j++) {
  62. ((UIButton *)self.buttonArray[j]).backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  63. }
  64. ((UIButton *)self.buttonArray[button.tag]).backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  65. if (self.delegate && [self.delegate respondsToSelector:@selector(shapeSelectView:tag:)]) {
  66. [self.delegate shapeSelectView:self tag:button.tag];
  67. }
  68. }
  69. @end