123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // CPDFAnnotationBaseViewController.m
- // compdfkit-tools
- //
- // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- //
- // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- // This notice may not be removed from this file.
- //
- #import "CPDFAnnotationBaseViewController.h"
- #import "CPDFAnnotationBaseViewController_Header.h"
- @interface CPDFAnnotationBaseViewController () <CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CPDFOpacitySliderViewDelegate>
- @end
- @implementation CPDFAnnotationBaseViewController
- #pragma mark - Initializers
- - (instancetype)initWithStyle:(CAnnotStyle *)annotStyle {
- if (self = [super init]) {
- self.annotStyle = annotStyle;
- }
- return self;
- }
- #pragma mark - ViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.titleLabel = [[UILabel alloc] init];
- self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
- self.titleLabel.font = [UIFont systemFontOfSize:20];
- self.titleLabel.adjustsFontSizeToFitWidth = YES;
- [self.view addSubview:self.titleLabel];
-
- self.backBtn = [[UIButton alloc] init];
- self.backBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- [self.backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBaseImageBack" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
- [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.backBtn];
-
- self.sampleView = [[CPDFAnnotationSampleView alloc] init];
- self.sampleView.backgroundColor = [UIColor whiteColor];
- self.sampleView.layer.borderColor = [UIColor purpleColor].CGColor;
- self.sampleView.layer.borderWidth = 1.0;
- self.sampleView.fillColor = [UIColor yellowColor];
- self.sampleView.opcity = 1.0;
- self.sampleView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
- [self.view addSubview:self.sampleView];
-
- self.colorView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 190, self.view.frame.size.width, 90)];
- self.colorView.delegate = self;
- self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [self.view addSubview:self.colorView];
-
- self.opacitySliderView = [[CPDFOpacitySliderView alloc] init];
- self.opacitySliderView.delegate = self;
- self.opacitySliderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [self.view addSubview:self.opacitySliderView];
-
- self.view.backgroundColor = [UIColor whiteColor];
- [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
- [self commomInitTitle];
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
- self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
- self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
- self.sampleView.frame = CGRectMake((self.view.frame.size.width - 300)/2, 60, 300, 120);
- self.opacitySliderView.frame = CGRectMake(10, 280, self.view.frame.size.width - 20, 90);
- self.colorPicker.frame = self.view.frame;
- }
- - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
- [self updatePreferredContentSizeWithTraitCollection:newCollection];
- }
- #pragma mark - Protect Methods
- - (void)commomInitTitle {
- self.titleLabel.text = NSLocalizedString(@"Note", nil);
- self.sampleView.selecIndex = CPDFSamplesHighlight;
- self.colorView.colorLabel.text = NSLocalizedString(@"Color:", nil);
- }
- - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
- self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 270 : 420);
- }
- #pragma mark - Action
- - (void)buttonItemClicked_back:(id)sender {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - CPDFColorSelectViewDelegate
- - (void)selectColorView:(CPDFColorSelectView *)select {
- _colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
- _colorPicker.delegate = self;
- _colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- _colorPicker.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.colorPicker];
- }
- - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
- self.sampleView.fillColor = color;
- [self.sampleView setNeedsDisplay];
- }
- #pragma mark - CPDFColorPickerViewDelegate
- - (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
- self.sampleView.fillColor = color;
- [self.sampleView setNeedsDisplay];
- }
- #pragma mark - CPDFOpacitySliderViewDelegate
- - (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
- self.sampleView.opcity = opacity;
- [self.sampleView setNeedsDisplay];
- }
- @end
|