123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //
- // CPDFShapeCircleViewController.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 "CPDFShapeCircleViewController.h"
- #import "CPDFShareCircleViewController_Header.h"
- @interface CPDFShapeCircleViewController () <CPDFThicknessSliderViewDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate>
- @end
- @implementation CPDFShapeCircleViewController
- #pragma mark - Initializers
- - (instancetype)initWithStyle:(CAnnotStyle *)annotStyle selectIndex:(NSInteger)index title:(NSString *)title {
- if (self = [super init]) {
- self.annotStyle = annotStyle;
- self.index = index;
- self.titles = title;
- }
- return self;
- }
- #pragma mark - ViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- _thicknessView = [[CPDFThicknessSliderView alloc] init];
- _thicknessView.delegate = self;
- _thicknessView.thicknessSlider.value = 4.0;
- _thicknessView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [self.view addSubview:self.thicknessView];
-
- self.dottedView = [[CPDFThicknessSliderView alloc] init];
- self.dottedView.delegate = self;
- self.dottedView.thicknessSlider.value = 0.0;
- self.dottedView.thicknessSlider.minimumValue = 0.0;
- self.dottedView.thicknessSlider.maximumValue = 10.0;
- self.dottedView.startLabel.text = @"0";
- self.dottedView.endLabel.text = @"10";
- self.dottedView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [self.view addSubview:self.dottedView];
-
- self.fillColorSelectView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 280, self.view.frame.size.width, 90)];
- self.fillColorSelectView.delegate = self;
- self.fillColorSelectView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [self.view addSubview:self.fillColorSelectView];
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
- self.opacitySliderView.frame = CGRectMake(10, 370, self.view.frame.size.width - 20, 90);
- self.thicknessView.frame = CGRectMake(10, 450, self.view.frame.size.width - 20, 90);
- self.dottedView.frame = CGRectMake(10, 540, self.view.frame.size.width - 20, 90);
- }
- - (void)commomInitTitle {
- self.sampleView.fillColor = self.annotStyle.color;
- self.sampleView.fillShapeColor = [UIColor whiteColor];
- self.sampleView.thickness = 4.0;
- self.fillColorSelectView.colorLabel.text = NSLocalizedString(@"Fill:", nil);
- self.thicknessView.titleLabel.text = NSLocalizedString(@"Thickness:", nil);
- self.colorView.colorLabel.text = NSLocalizedString(@"Border:", nil);
- self.dottedView.titleLabel.text = NSLocalizedString(@"Dotted", nil);
- self.sampleView.selecIndex = self.index;
- self.titleLabel.text = self.titles;
- }
- - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
- self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 370 : 660);
- }
- #pragma mark - CPDFThicknessSliderViewDelegate
- - (void)thicknessSliderView:(CPDFThicknessSliderView *)thicknessSliderView thickness:(CGFloat)thickness {
- if (thicknessSliderView == self.thicknessView) {
- self.sampleView.thickness = thickness;
- [self.sampleView setNeedsDisplay];
- } else if (thicknessSliderView == self.dottedView) {
- self.sampleView.dotted = thickness;
- [self.sampleView setNeedsDisplay];
- }
- }
- #pragma mark - CPDFColorSelectViewDelegate
- - (void)selectColorView:(CPDFColorSelectView *)select {
- if (select == self.colorView) {
- self.colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
- self.colorPicker.delegate = self;
- self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- self.colorPicker.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.colorPicker];
- } else if (select == self.fillColorSelectView) {
- self.fillColorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
- self.fillColorPicker.delegate = self;
- self.fillColorPicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- self.fillColorPicker.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.fillColorPicker];
- }
- }
- - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
- if (select == self.colorView) {
- self.sampleView.fillColor = color;
- self.annotStyle.color = color;
- [self.sampleView setNeedsDisplay];
- if (self.delegate && [self.delegate respondsToSelector:@selector(circleViewController:annotStyle:)]) {
- [self.delegate circleViewController:self annotStyle:self.annotStyle];
- }
- } else if (select == self.fillColorSelectView) {
- self.sampleView.fillShapeColor = color;
- self.annotStyle.fillColor = color;
- [self.sampleView setNeedsDisplay];
- if (self.delegate && [self.delegate respondsToSelector:@selector(circleViewController:annotStyle:)]) {
- [self.delegate circleViewController:self annotStyle:self.annotStyle];
- }
- }
- }
- #pragma mark - CPDFColorPickerViewDelegate
- - (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
- if (colorPickerView == self.colorPicker) {
- self.sampleView.fillColor = color;
- [self.sampleView setNeedsDisplay];
- } else if (colorPickerView == self.fillColorPicker) {
- self.sampleView.fillShapeColor = color;
- [self.sampleView setNeedsDisplay];
- }
- }
- @end
|