CPDFAnnotationBaseViewController.m 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // CPDFAnnotationBaseViewController.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 "CPDFAnnotationBaseViewController.h"
  13. #import "CPDFAnnotationBaseViewController_Header.h"
  14. @interface CPDFAnnotationBaseViewController () <CPDFColorSelectViewDelegate>
  15. @property (nonatomic, strong) CAnnotStyle *annotStyle;
  16. @end
  17. @implementation CPDFAnnotationBaseViewController
  18. #pragma mark - Initializers
  19. - (instancetype)initWithStyle:(CAnnotStyle *)annotStyle {
  20. if (self = [super init]) {
  21. self.annotStyle = annotStyle;
  22. }
  23. return self;
  24. }
  25. #pragma mark - ViewController Methods
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. self.titleLabel = [[UILabel alloc] init];
  30. self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  31. self.titleLabel.font = [UIFont systemFontOfSize:20];
  32. self.titleLabel.adjustsFontSizeToFitWidth = YES;
  33. [self.view addSubview:self.titleLabel];
  34. self.sampleView = [[CPDFAnnotationSampleView alloc] init];
  35. self.sampleView.backgroundColor = [UIColor whiteColor];
  36. self.sampleView.layer.borderColor = [UIColor purpleColor].CGColor;
  37. self.sampleView.layer.borderWidth = 1.0;
  38. self.sampleView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  39. [self.view addSubview:self.sampleView];
  40. self.colorView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 190, self.view.frame.size.width, 90)];
  41. self.colorView.delegate = self;
  42. self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  43. [self.view addSubview:self.colorView];
  44. self.opacitySliderView = [[CPDFOpacitySliderView alloc] init];
  45. self.opacitySliderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  46. [self.view addSubview:self.opacitySliderView];
  47. self.view.backgroundColor = [UIColor whiteColor];
  48. [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
  49. [self commomInitTitle];
  50. }
  51. - (void)viewWillLayoutSubviews {
  52. self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
  53. self.sampleView.frame = CGRectMake((self.view.frame.size.width - 300)/2, 60, 300, 120);
  54. self.opacitySliderView.frame = CGRectMake(0, 280, self.view.frame.size.width, 90);
  55. self.colorPicker.frame = self.view.frame;
  56. }
  57. - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  58. [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
  59. [self updatePreferredContentSizeWithTraitCollection:newCollection];
  60. }
  61. - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection
  62. {
  63. self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 270 : 420);
  64. }
  65. #pragma mark - Protect Methods
  66. - (void)commomInitTitle {
  67. self.titleLabel.text = NSLocalizedString(@"Note", nil);
  68. }
  69. #pragma mark - CPDFColorSelectViewDelegate
  70. - (void)colorSelect:(CPDFColorSelectView *)select {
  71. _colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
  72. _colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  73. _colorPicker.backgroundColor = [UIColor whiteColor];
  74. [self.view addSubview:self.colorPicker];
  75. }
  76. @end