CPDFShapeCircleViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // CPDFShapeCircleViewController.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 "CPDFShapeCircleViewController.h"
  13. #import "CPDFShareCircleViewController_Header.h"
  14. @interface CPDFShapeCircleViewController () <CPDFThicknessSliderViewDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate>
  15. @end
  16. @implementation CPDFShapeCircleViewController
  17. #pragma mark - Initializers
  18. - (instancetype)initWithStyle:(CAnnotStyle *)annotStyle selectIndex:(NSInteger)index title:(NSString *)title {
  19. if (self = [super init]) {
  20. self.annotStyle = annotStyle;
  21. self.index = index;
  22. self.titles = title;
  23. }
  24. return self;
  25. }
  26. #pragma mark - ViewController Methods
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. _thicknessView = [[CPDFThicknessSliderView alloc] init];
  31. _thicknessView.delegate = self;
  32. _thicknessView.thicknessSlider.value = 4.0;
  33. _thicknessView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  34. [self.view addSubview:self.thicknessView];
  35. self.dottedView = [[CPDFThicknessSliderView alloc] init];
  36. self.dottedView.delegate = self;
  37. self.dottedView.thicknessSlider.value = 0.0;
  38. self.dottedView.thicknessSlider.minimumValue = 0.0;
  39. self.dottedView.thicknessSlider.maximumValue = 10.0;
  40. self.dottedView.startLabel.text = @"0";
  41. self.dottedView.endLabel.text = @"10";
  42. self.dottedView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  43. [self.view addSubview:self.dottedView];
  44. self.fillColorSelectView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 280, self.view.frame.size.width, 90)];
  45. self.fillColorSelectView.delegate = self;
  46. self.fillColorSelectView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  47. [self.view addSubview:self.fillColorSelectView];
  48. }
  49. - (void)viewWillLayoutSubviews {
  50. [super viewWillLayoutSubviews];
  51. self.opacitySliderView.frame = CGRectMake(10, 370, self.view.frame.size.width - 20, 90);
  52. self.thicknessView.frame = CGRectMake(10, 450, self.view.frame.size.width - 20, 90);
  53. self.dottedView.frame = CGRectMake(10, 540, self.view.frame.size.width - 20, 90);
  54. }
  55. - (void)commomInitTitle {
  56. self.sampleView.fillColor = self.annotStyle.color;
  57. self.sampleView.fillShapeColor = [UIColor whiteColor];
  58. self.sampleView.thickness = 4.0;
  59. self.fillColorSelectView.colorLabel.text = NSLocalizedString(@"Fill:", nil);
  60. self.thicknessView.titleLabel.text = NSLocalizedString(@"Thickness:", nil);
  61. self.colorView.colorLabel.text = NSLocalizedString(@"Border:", nil);
  62. self.dottedView.titleLabel.text = NSLocalizedString(@"Dotted", nil);
  63. self.sampleView.selecIndex = self.index;
  64. self.titleLabel.text = self.titles;
  65. }
  66. - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
  67. self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 370 : 660);
  68. }
  69. #pragma mark - CPDFThicknessSliderViewDelegate
  70. - (void)thicknessSliderView:(CPDFThicknessSliderView *)thicknessSliderView thickness:(CGFloat)thickness {
  71. if (thicknessSliderView == self.thicknessView) {
  72. self.sampleView.thickness = thickness;
  73. [self.sampleView setNeedsDisplay];
  74. } else if (thicknessSliderView == self.dottedView) {
  75. self.sampleView.dotted = thickness;
  76. [self.sampleView setNeedsDisplay];
  77. }
  78. }
  79. #pragma mark - CPDFColorSelectViewDelegate
  80. - (void)selectColorView:(CPDFColorSelectView *)select {
  81. if (select == self.colorView) {
  82. self.colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
  83. self.colorPicker.delegate = self;
  84. self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  85. self.colorPicker.backgroundColor = [UIColor whiteColor];
  86. [self.view addSubview:self.colorPicker];
  87. } else if (select == self.fillColorSelectView) {
  88. self.fillColorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
  89. self.fillColorPicker.delegate = self;
  90. self.fillColorPicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  91. self.fillColorPicker.backgroundColor = [UIColor whiteColor];
  92. [self.view addSubview:self.fillColorPicker];
  93. }
  94. }
  95. - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
  96. if (select == self.colorView) {
  97. self.sampleView.fillColor = color;
  98. self.annotStyle.color = color;
  99. [self.sampleView setNeedsDisplay];
  100. if (self.delegate && [self.delegate respondsToSelector:@selector(circleViewController:annotStyle:)]) {
  101. [self.delegate circleViewController:self annotStyle:self.annotStyle];
  102. }
  103. } else if (select == self.fillColorSelectView) {
  104. self.sampleView.fillShapeColor = color;
  105. self.annotStyle.fillColor = color;
  106. [self.sampleView setNeedsDisplay];
  107. if (self.delegate && [self.delegate respondsToSelector:@selector(circleViewController:annotStyle:)]) {
  108. [self.delegate circleViewController:self annotStyle:self.annotStyle];
  109. }
  110. }
  111. }
  112. #pragma mark - CPDFColorPickerViewDelegate
  113. - (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
  114. if (colorPickerView == self.colorPicker) {
  115. self.sampleView.fillColor = color;
  116. [self.sampleView setNeedsDisplay];
  117. } else if (colorPickerView == self.fillColorPicker) {
  118. self.sampleView.fillShapeColor = color;
  119. [self.sampleView setNeedsDisplay];
  120. }
  121. }
  122. @end