12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- //
- // CPDFTextViewController.m
- // PDFViewer
- //
- // Created by kdan on 2022/11/19.
- //
- #import "CPDFTextViewController.h"
- #import "CPDFTextView.h"
- #import "CPDFTextPreview.h"
- #import "CPDFDataModel.h"
- #import "Masonry.h"
- @interface CPDFTextViewController ()
- @end
- @implementation CPDFTextViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- _textPreview = [[CPDFTextPreview alloc] init];
- _textView = [[CPDFTextView alloc] init];
- _dataModel = [[CPDFDataModel alloc] init];
-
- [self.view addSubview:_textPreview];
- [self.view addSubview:_textView];
-
- UIEdgeInsets previewPadding = UIEdgeInsetsMake(0, 0, self.view.bounds.size.height / 3, 0);
- [_textPreview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view).with.insets(previewPadding);
- }];
- UIEdgeInsets textViewPadding = UIEdgeInsetsMake(430, 0, 0, 0);
- [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view).with.insets(textViewPadding);
- }];
- [self addTargets];
- }
- - (void)addTargets {
-
- for (NSInteger i = 0; i < _textView.colorArray.count; ++i) {
- [_textView.colorArray[i] addTarget:self action:@selector(onColorBtnClicked:) forControlEvents:UIControlEventTouchDown];
- }
-
- [_textView.opacitySlider addTarget:self action:@selector(onOpacityChanged:) forControlEvents:UIControlEventValueChanged];
- [_textView.textScaleSlider addTarget:self action:@selector(onTextScaleChanged:) forControlEvents:UIControlEventValueChanged];
- [_textView.tileSwitch addTarget:self action:@selector(onTileSwitchChanged:) forControlEvents:UIControlEventValueChanged];
- }
- - (void)onColorBtnClicked:(UIButton *)sender {
- _textPreview.watermarkLabel.textColor = sender.backgroundColor;
- [_dataModel setTextColor:sender.backgroundColor];
- }
- - (void)onOpacityChanged:(UISlider *)sender {
- _textPreview.watermarkLabel.alpha = 1 - sender.value;
- [_dataModel setWatermarkOpacity:1 - sender.value];
- }
- - (void)onTextScaleChanged:(UISlider *)sender {
- sender.minimumValue = 24;
- sender.maximumValue = 70;
- _textPreview.watermarkLabel.font = [_textPreview.watermarkLabel.font fontWithSize:sender.value];
- [_textPreview.watermarkLabel sizeToFit];
- CGRect frame = _textPreview.watermarkLabel.frame;
- frame.origin = CGPointMake(_textPreview.bounds.size.width / 2 - _textPreview.watermarkLabel.frame.size.width / 2, _textPreview.bounds.size.height / 2 - _textPreview.watermarkLabel.frame.size.height / 2);
- _textPreview.watermarkLabel.frame = frame;
-
- _textPreview.rotationBtn.frame = CGRectMake(_textPreview.bounds.size.width / 2 + _textPreview.watermarkLabel.frame.size.width / 2 - 10, _textPreview.bounds.size.height / 2 + _textPreview.watermarkLabel.frame.size.height / 2 - 10, 20, 20);
- [_dataModel setWatermarkScale:sender.value / 24];
- }
- - (void)onTileSwitchChanged:(UISwitch *) sender {
- if ([sender isOn]) {
- _dataModel.isTile = YES;
- } else {
- _dataModel.isTile = NO;
- }
- }
- @end
|