CPDFTextViewController.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // CPDFTextViewController.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/19.
  6. //
  7. #import "CPDFTextViewController.h"
  8. #import "CPDFTextView.h"
  9. #import "CPDFTextPreview.h"
  10. #import "CPDFDataModel.h"
  11. #import "Masonry.h"
  12. @interface CPDFTextViewController ()
  13. @end
  14. @implementation CPDFTextViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. _textPreview = [[CPDFTextPreview alloc] init];
  19. _textView = [[CPDFTextView alloc] init];
  20. _dataModel = [[CPDFDataModel alloc] init];
  21. [self.view addSubview:_textPreview];
  22. [self.view addSubview:_textView];
  23. UIEdgeInsets previewPadding = UIEdgeInsetsMake(0, 0, self.view.bounds.size.height / 3, 0);
  24. [_textPreview mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.edges.equalTo(self.view).with.insets(previewPadding);
  26. }];
  27. UIEdgeInsets textViewPadding = UIEdgeInsetsMake(430, 0, 0, 0);
  28. [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.edges.equalTo(self.view).with.insets(textViewPadding);
  30. }];
  31. [self addTargets];
  32. }
  33. - (void)addTargets {
  34. for (NSInteger i = 0; i < _textView.colorArray.count; ++i) {
  35. [_textView.colorArray[i] addTarget:self action:@selector(onColorBtnClicked:) forControlEvents:UIControlEventTouchDown];
  36. }
  37. [_textView.opacitySlider addTarget:self action:@selector(onOpacityChanged:) forControlEvents:UIControlEventValueChanged];
  38. [_textView.textScaleSlider addTarget:self action:@selector(onTextScaleChanged:) forControlEvents:UIControlEventValueChanged];
  39. [_textView.tileSwitch addTarget:self action:@selector(onTileSwitchChanged:) forControlEvents:UIControlEventValueChanged];
  40. }
  41. - (void)onColorBtnClicked:(UIButton *)sender {
  42. _textPreview.watermarkLabel.textColor = sender.backgroundColor;
  43. [_dataModel setTextColor:sender.backgroundColor];
  44. }
  45. - (void)onOpacityChanged:(UISlider *)sender {
  46. _textPreview.watermarkLabel.alpha = 1 - sender.value;
  47. [_dataModel setWatermarkOpacity:1 - sender.value];
  48. }
  49. - (void)onTextScaleChanged:(UISlider *)sender {
  50. sender.minimumValue = 24;
  51. sender.maximumValue = 70;
  52. _textPreview.watermarkLabel.font = [_textPreview.watermarkLabel.font fontWithSize:sender.value];
  53. [_textPreview.watermarkLabel sizeToFit];
  54. CGRect frame = _textPreview.watermarkLabel.frame;
  55. 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);
  56. _textPreview.watermarkLabel.frame = frame;
  57. _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);
  58. [_dataModel setWatermarkScale:sender.value / 24];
  59. }
  60. - (void)onTileSwitchChanged:(UISwitch *) sender {
  61. if ([sender isOn]) {
  62. _dataModel.isTile = YES;
  63. } else {
  64. _dataModel.isTile = NO;
  65. }
  66. }
  67. @end